Share via


LayoutParams not working to set the height and width

Question

Thursday, November 21, 2013 5:17 PM

im trying to do this

var lay = new LinearLayout(this);
ViewGroup.LayoutParams parms = lay.LayoutParameters;
parms.Height = 200;

But it says parms is null and stuff... and if a put params it gots like cyan color and red underlined... Any tips?

All replies (7)

Thursday, November 21, 2013 10:13 PM

Try this instead:

var lay = new LinearLayout(this);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.WrapContent, 200); //Width, Height
lay.LayoutParameters = parms;

Friday, November 22, 2013 2:18 AM

You cannot be sure that he needs to use LinearLayout.LayoutParams that is up to the Parent layout type to determine.


Friday, November 22, 2013 6:27 AM

Hi, I'm trying to resize a child Relative Layout in runtime, I tried this two ways but none works, have you any idea of how to do that? this.imgMoreBasic.Click += (sender,args)=> { if (FSViewController.IsBusy()) return; try { detailBasic.LayoutParameters.Height = RelativeLayout.LayoutParams.WrapContent; detailBasic.RefreshDrawableState();

                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    }
                };
                this.imgMoreDescription.Click += (sender, args) =>
                {
                    if (FSViewController.IsBusy())
                        return;
                    try
                    {
                        detailDescription.LayoutParameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FillParent, RelativeLayout.LayoutParams.WrapContent);
                        detailBasic.RefreshDrawableState();

                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    }
                };

Friday, November 22, 2013 12:21 PM

It didnt worked...

I am creating a simple linearLayout with vertical orientation and i want it to be 700,500 and i ll set a alertDialog view to be him but im not being able to change its size, and then i ll add buttons and imageViews foreach string in a list i have... but how can i control its sizes?

I just need to make this LinearLayout layoutMaster = new LinearLayout(this); to be like 700,500 and put it in a alertDialog just that


Friday, November 22, 2013 1:23 PM

This is whats not working

LinearLayout layoutMaster = new LinearLayout(this);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams (700, 500);
layoutMaster.LayoutParameters = parms;
layoutMaster.SetBackgroundColor(Android.Graphics.Color.Rgb(240,240,240));
var builder = new AlertDialog.Builder(this);
builder.SetView(layoutMaster);
builder.Create().Show();

But all i got is a thin almost black rectangle >:


Wednesday, April 15, 2015 8:57 AM

Was there anyone solve this problem ?


Tuesday, January 12, 2016 8:08 AM

@HiltonMenezesHilton , I am having same problem. But, you can set the height and width of the layout like this :

layoutMaster.SetMinimumHeight(500); layoutMaster.SetMinimumWidth(700);