【问题标题】:How to adjust a label "inside" of a image Xamarin Forms如何调整图像 Xamarin Forms 的“内部”标签
【发布时间】:2016-10-29 02:28:34
【问题描述】:
我正在尝试在我的图像中添加标签,我无法使用 Margin 属性,因为某些原因它不起作用,直到现在我有这个:
而我想要的是这个:
XAML:
<StackLayout Orientation="Vertical">
<Label HorizontalOptions="Center" Text="something" TextColor="Black"/>
<Image HorizontalOptions="Center" Source="spin.png"/>
</StackLayout>
【问题讨论】:
标签:
c#
xaml
xamarin.forms
【解决方案1】:
您需要Grid 而不是StackLayout(注意Label 和Image 如何位于同一行和同一列):
<Grid HorizontalOptions="Center"
VerticalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image HorizontalOptions="Center"
Source="spin.png"
Grid.Row="0"
Grid.Column="0"/>
<Label HorizontalOptions="Center"
Text="something"
TextColor="Black"
Grid.Row="0"
Grid.Column="0"/>
</Grid>
由于Label 列在上述 XAML 代码中的 Image 下方,因此 Label 将绘制在 Image 上方。
您也可以使用AbsoluteLayout,这是另一种擅长分层的布局。