Xamarin中的网格中的图像如何居中
我正在开发Xamarin。形成移动应用程序,并尝试将2按钮的中心和图像中心和图像,我如何中心和图像在网格XAML标签中,请参阅下面使用的XAML代码,并将其放置在移动应用程序屏幕的中心。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoApp.Views.MainPage"
NavigationPage.HasNavigationBar="False">
<ContentPage.Content>
<Grid HorizontalOptions="CenterAndExpand" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center" >
<Image Grid.Row="0" Grid.Column="0" Source="RegisterUser" WidthRequest="100" HeightRequest="81" HorizontalOptions="Center" VerticalOptions="Center" />
</StackLayout>
<Button Text="Sign-In" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" TextColor="White"
Grid.Row="2" Grid.Column="0"
BorderRadius="4" BorderWidth="1"
BackgroundColor="LightGray" />
<Button Text="Register" TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Grid.Row="2" Grid.Column="1"
BorderRadius="4" BorderWidth="1"
BackgroundColor="LightGray" />
</Grid>
</ContentPage.Content>
</ContentPage>
I'm developing a Xamarin. Form mobile apps and trying to center and image above 2 buttons, how can I center and image in a grid XAML tag, see XAML code below in which I'm using, and having difficulty place it in the center of the mobile app screen.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoApp.Views.MainPage"
NavigationPage.HasNavigationBar="False">
<ContentPage.Content>
<Grid HorizontalOptions="CenterAndExpand" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center" >
<Image Grid.Row="0" Grid.Column="0" Source="RegisterUser" WidthRequest="100" HeightRequest="81" HorizontalOptions="Center" VerticalOptions="Center" />
</StackLayout>
<Button Text="Sign-In" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" TextColor="White"
Grid.Row="2" Grid.Column="0"
BorderRadius="4" BorderWidth="1"
BackgroundColor="LightGray" />
<Button Text="Register" TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Grid.Row="2" Grid.Column="1"
BorderRadius="4" BorderWidth="1"
BackgroundColor="LightGray" />
</Grid>
</ContentPage.Content>
</ContentPage>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的网格有2个COLS,因此您的
stacklayout
需要跨越它们才能集中在整个网格上your grid has 2 cols, so your
StackLayout
needs to span them in order to be centered across the entire grid