Xaml 如果文本变大,则将内容居中
我有这个xaml示例:Xaml 如果文本变大,则将内容居中,xaml,xamarin.forms,layout,Xaml,Xamarin.forms,Layout,我有这个xaml示例: <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> <StackLayout BackgroundColor="LightBlue"> <Label Text="ABC" HorizontalTextAlig
<StackLayout Orientation="Horizontal"
HorizontalOptions="CenterAndExpand">
<StackLayout BackgroundColor="LightBlue">
<Label Text="ABC"
HorizontalTextAlignment="Center" />
<Label Text="L"
HorizontalTextAlignment="Center"></Label>
</StackLayout>
<BoxView BackgroundColor="Red" />
<StackLayout BackgroundColor="LightGreen">
<Label Text="ABC"
HorizontalTextAlignment="Center" />
<Label Text="C"
HorizontalTextAlignment="Center"></Label>
</StackLayout>
</StackLayout>
产生此输出的:但如果四个标签中的一个变大,则不再居中:
我的目标是以下布局,这取决于最大的标签:
我是初学者。所以我希望有人能帮我找到正确的布局。
谢谢StackLayout确实不是这里的最佳选择,因为它动态地占用大小(即取决于其内容)。这里更好的方法是使用Xamarin.Forms的布局 这样,您就可以拥有一个包含3列的网格。然后,将您的宽度设置为星形(*)。正如您在部分中所看到的,将列的宽度设置为星形意味着: 星形–按比例分配剩余的行高或列宽(在XAML中后跟*的数字)
基本上,您将整个屏幕宽度分成3个相等的部分,每个部分的屏幕宽度为33,3(3%)。然后,可以根据需要对齐容器中的元素