Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto width or height in xamarin forms

As we know in android we can use

android:width='wrap_content'
android:height='match_parent'

to set width or height of the views.
but, in xamarin forms we cannot use that.

so how can i set dynamic width or height for my xamarin forms component?
like match_parent or wrap_content in android

like image 386
cahyo Avatar asked Jan 16 '26 21:01

cahyo


1 Answers

In Xamarin.Forms you do the same using the LayoutOptions.

Let's say you have a Button which you want to grow horizontally (width) as its parent grow, you use:

var button4 = new Button {Text = "Click Me!", HorizontalOptions=LayoutOptions.FillAndExpand, VerticalOptions=LayoutOptions.Center};

LayoutOptions.FillAndExpand means it will take all the posible space available in its parent view (with some exceptions).

in XAML that'd be:

<Button Text="Click Me!"
        HorizontalOptions="FillAndExpand"
        VerticalOptions="Center" />

Suggest you to see the Getting Started of Xamarin Forms.

like image 175
pinedax Avatar answered Jan 19 '26 19:01

pinedax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!