Spinner - Xamarin

Asked

Viewed 106 times

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 ???

  • Got anything done? What exactly can’t you do? Put the code here to facilitate help.

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 it that way:

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’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.