Spinner - Xamarin

2

I need to create a spinner by programming code and define:

  • layout_height: match_parent
  • layout_weight: 10
  • layout_width: wrap_content

Spinner sp = new Spinner (this);

  

sp.Layout_height ???

    
asked by anonymous 28.10.2015 / 19:32

1 answer

1

To programmatically change the size of a view use LayoutParameters .

Example:

LinearLayout.LayoutParams parametros = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.MatchParent, 10);
Spinner sp = new Spinner(this);
sp.LayoutParameters = parametros;

Remembering that this constructor has the following signature: LayoutParams(int width, int height, int weight)

Or if you prefer you can do this:

Spinner sp = new Spinner(this);
LinearLayout.LayoutParams parametros = (LinearLayout.LayoutParams)sp.LayoutParameters;
parametros.Height = LinearLayout.LayoutParams.MatchParent;
parametros.Width = LinearLayout.LayoutParams.WrapContent;
parametros.Weight = 10;

I hope I have helped.

    
20.05.2016 / 19:05