I am creating a custom Dialog
which includes a LinearLayout
and a text and button in it. I set the Orientation to the layout to Vertical. So far so good but the problem starts when I try to apply some margins to the layout so I'll had gap between text and the button.
This is a Xamarin.Forms solution and the code is in Android project. I simply want to add some space between the text and the button.
Can you please help me to solve this?
Best,
Suat
LinearLayout layout = new LinearLayout(context);
layout.Orientation = Orientation.Vertical;
layout.SetGravity(GravityFlags.Center);
Button CancelButton = new Button(context);
CancelButton.Text = "İptal";
CancelButton.Click += CancelButton_ClickHandler;
CancelButton.SetShadowLayer(2, 1, 1, Color.Black);
GradientDrawable shape = new GradientDrawable();
shape.SetCornerRadius(8);
shape.SetColor(Color.ParseColor("#12a3ff"));
CancelButton.SetBackgroundDrawable(shape);
CancelButton.Visibility = ViewStates.Invisible;
TextView statusText = new TextView(context);
statusText.TextAlignment = TextAlignment.Center;
if (cancellationMessage == null)
statusText.Text = "İşlemin tamamlanması zaman alacaktır. Devam edebilir ya da işlemi şimdi iptal edebilirsiniz.";
else
statusText.Text = cancellationMessage;
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
lp.SetMargins(20, 20, 20, 20);
layoutAddView(statusText);
layoutAddView(CancelButton);
layoutLayoutParameters = lp; // program keep stopping here
This method won't work either.
layoutAddView(statusText, lp);
layoutAddView(CancelButton, lp);