我正在尝试水平居中StackLayout
在一个ScrollView
。但是,那StackLayout
不是水平居中(它左对齐)。我尝试将ScrollView
但整个视图是不可滚动的——只有中心部分是可滚动的。
<ScrollView BackgroundColor="Teal">
<StackLayout Spacing="5"
Padding="30"
WidthRequest="400"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
BackgroundColor="Transparent">
<Label Text="Test"/>
<Label Text="Test"/>
<Label Text="Test"/>
<Label Text="Test"/>
</StackLayout>
</ScrollView>
居中适用于 2 个嵌套StackLayout
元素,但它不与ScrollView
。有任何想法吗?
您有几个选项,下面示例中的每个标签都应居中显示。
关键是 StackLayout 的布局基于其内容。您可能认为可以按照您的方式将整个 StackLayout 居中,但至少作为 ScrollView 的内容,它不会那样工作。但是将该 StackLayout 的子级居中将在 ScrollView 中居中:
<ScrollView BackgroundColor="Teal">
<StackLayout Spacing="5"
Padding="30"
WidthRequest="400"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
BackgroundColor="Transparent">
<Label Text="Test" HorizontalOptions="Center"/>
<StackLayout HorizontalOptions="Center">
<Label Text="Test"/>
</StackLayout>
</StackLayout>
</ScrollView>
在这种情况下,外部 StackLayout 上的 HorizontalOptions 似乎没有任何影响,但我会使用 FillAndExpand 作为记录填充 ScrollView 整个水平空间的意图的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)