Reputation: 231
Right now I'm developing mobile App with Xamarin, I want to know how to put multiple controls in one line for example, how would I put two equal sized button in one line?
I tried to dragged them into one line but it won't work. I'm guessing there is something call divider or something else. Please help, thank you
Upvotes: 1
Views: 3281
Reputation: 1
Xamarin Cross Platform:
Android,IOS and UWP
Use this Code...
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Button Text="Next" Command="{Binding NextQuestion}" BackgroundColor="DimGray" TextColor="Black"/>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Button Text="End to Exam" BackgroundColor="DarkGray" TextColor="Black"/>
</StackLayout>
Upvotes: 0
Reputation: 4173
For those who prefer Code behind:
Button Button1 = new Button { Text = " Button 1" };
Button Button2 = new Button { Text = " Button 2" };
StackLayout myStackLayout = new StackLayout {
Children = {
Button1,
Button2
},
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
For more info check the following link https://forums.xamarin.com/discussion/39101/put-two-buttons-on-the-same-line
Upvotes: 1
Reputation: 3559
This is not a Xamarin specific question. You need to look into the Android documentation to see how you can make proper layouts.
In your case you want two equally sized controls in one view. You can do that with something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2" />
</LinearLayout>
The android:layout_weight="2" will distribute the size of the 2 buttons over the view.
Upvotes: 1