我正在尝试使用Visual Studio Xamarin制作适用于iOS和Android的应用程序,但布局根本不起作用。这是我使用的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Test" x:Class="Test.MainPage" BackgroundColor="Black">
<StackLayout>
<!-- Place your controls here -->
<Label x:Name="TextLabel"
Text="Title label:"
TextColor="White"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
Margin="0,250,0,0"
/>
<Button x:Name="OpenFood"
Text=""
TextColor="Yellow"
FontSize="Large"
FontAttributes="Bold"
Clicked="OpenFood_Pressed"
Margin="0,0,0,250"
/>
<Button x:Name="NewFood"
Text=" Display label button "
BorderColor="Gray"
BorderWidth="1"
BorderRadius="10"
TextColor="White"
FontSize="Large"
FontAttributes="Bold"
Clicked="NewFood_Pressed"
HorizontalOptions="Center"
/>
</StackLayout>
</ContentPage>
预览窗口看起来像我想要的,但在设备上根本不适合: Click here for image
编辑:告诉你我想要什么:我想在屏幕底部找到Display label button
,在屏幕中间看到TextLabel
和OpenFood
。
答案 0 :(得分:0)
您必须使用Xamarin中的VerticalOptions。您可以将Fill,Center,FillAndExpand添加到控件中,从而调整页面内的位置。
<Label x:Name="TextLabel"
Text="Title label:"
TextColor="White"
VerticalOptions="Center"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
Margin="0,250,0,0"
/>
<Button x:Name="OpenFood"
Text=""
VerticalOptions="Center"
TextColor="Yellow"
FontSize="Large"
FontAttributes="Bold"
Clicked="OpenFood_Pressed"
Margin="0,0,0,250"
/>
<Button x:Name="NewFood"
Text=" Display label button "
VerticalOptions="End"
HorizontalOptions="Center
BorderColor="Gray"
BorderWidth="1"
BorderRadius="10"
TextColor="White"
FontSize="Large"
FontAttributes="Bold"
Clicked="NewFood_Pressed"
HorizontalOptions="Center"
/>
</StackLayout>