如何在标签的“内部"调整标签? Xamarin形式的图像 [英] How to adjust a label "inside" of a image Xamarin Forms
本文介绍了如何在标签的“内部"调整标签? Xamarin形式的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在图像中放置标签,我无法使用Margin
属性,因为某种原因它不起作用,直到现在我有了它:
I'm trying to put a label inside of my image, I couldn't use a Margin
property, because some reason it's not working, untill now I have this :
我想要的是这个
XAML:
<StackLayout Orientation="Vertical">
<Label HorizontalOptions="Center" Text="something" TextColor="Black"/>
<Image HorizontalOptions="Center" Source="spin.png"/>
</StackLayout>
推荐答案
您需要使用Grid
而不是StackLayout
(请注意Label
和Image
如何在同一行和同一列中) :
You need a Grid
instead of a StackLayout
(notice how both the Label
and the Image
are in the same row and column):
<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
的顶部.
Because the Label
is listed beneath the Image
in the XAML code above, the Label
will be drawn on top of the Image
.
您还可以使用AbsoluteLayout
,这是另一种擅长分层的布局.
You also could have used an AbsoluteLayout
, which is another layout that is good at layering things.
这篇关于如何在标签的“内部"调整标签? Xamarin形式的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文