在我的Xamarin Forms应用程序中,我试图在移动界面上放置两个标签,一个在左下角,一个在右下角。
这是我目前的尝试。它是一种具有一行两列的网格布局,每个单元格中都有一个标签,左边的带有HorizontalTextAlightment="Start"
,右边的带有HorizontalTextAlightment="End"
...other unrelated controls...
<StackLayout Orientation="Horizontal" Spacing="0" Padding="15" VerticalOptions="End" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding DeviceId}" HorizontalTextAlignment="Start" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding Version}" HorizontalTextAlignment="End" Grid.Row="0" Grid.Column="1" />
</Grid>
</StackLayout>
</StackLayout>
这会产生不想要的结果:(v1.0-1应该向右对齐)
这就是我要的:
为什么将视图包装在中StackLayout
?AStacklayout
将分配所需的最小空间量。这就是为什么您看到屏幕截图1中显示的行为的原因。
如果您只有:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding DeviceId}" HorizontalTextAlignment="Start" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding Version}" HorizontalTextAlignment="End" Grid.Row="0" Grid.Column="1" />
</Grid>
您将看到所需的行为。
你也可以尝试使用HorizontalOptions
上Label
,而不是HorizontalTextAlignment
如果你确实需要使用StackLayout
,你可以尝试设置HorizontalOptions
的StackLayout
到FillAndExpand
。其中指出:
FillAndExpand –放置视图,使其没有填充,并占用布局将提供的尽可能多的空间。
参考: https : //developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/stack-layout/#Sizing
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句