How to adjust a label “inside” of a image Xamarin Forms

前端 未结 1 2014
情歌与酒
情歌与酒 2021-01-18 03:51

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 :

And wh

相关标签:
1条回答
  • 2021-01-18 04:41

    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>
    

    Because the Label is listed beneath the Image in the XAML code above, the Label will be drawn on top of the Image.

    You also could have used an AbsoluteLayout, which is another layout that is good at layering things.

    0 讨论(0)
提交回复
热议问题