这里是我想在Xamarin Forms中创建XAML的截图。我想在Xamarin Forms中创建Simple XAML
所以我想确切地知道什么是我可以把“62”在家长和“PSI”中心旁边的“62”。 它似乎需要使用RelativeLayout,但我无法创建完美的相同的东西。
感谢您的帮助!实现这一
这里是我想在Xamarin Forms中创建XAML的截图。我想在Xamarin Forms中创建Simple XAML
所以我想确切地知道什么是我可以把“62”在家长和“PSI”中心旁边的“62”。 它似乎需要使用RelativeLayout,但我无法创建完美的相同的东西。
感谢您的帮助!实现这一
的一种方式,是一种Grid
与Columns
和Rows
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" TextColor="Gray" Text="Healthy" />
<StackLayout HorizontalOptions="Center" Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
<Label Text="62" TextColor="Black" FontAttributes="Bold" FontSize="Medium" />
<Label Margin="0,10,0,0" Text="PSI" TextColor="Gray" />
</StackLayout>
<Label Grid.Row="2" Grid.Column="2" Text="Your image" />
</Grid>
就像亚历山德罗表示,GeralexGR回答是利用电网的好形式给出。 采取下一个样本,并修改您的需要
<Grid Margin="20" BackgroundColor="#EEEEEE">
<Frame CornerRadius="10" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="StartAndExpand" Margin="0, 20, 0, 0">
<Grid ColumnSpacing="0" RowSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
Text="Healthy" TextColor="Gray"
FontSize="Small" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Start" />
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"
Text="62" TextColor="Black"
FontSize="Large" FontAttributes="Bold"
HorizontalOptions="CenterAndExpand" HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"/>
<Label Grid.Row="1" Grid.Column="2"
Text="PSI" TextColor="LightGray"
FontSize="Medium" HorizontalOptions="Start" HorizontalTextAlignment="Start"
VerticalTextAlignment="Center"/>
<Image Grid.Row="2" Grid.Column="2"
Source="hearth.png" />
</Grid>
</Frame>
</Grid>
在用户界面上它看起来像这样 sample
您可以使用RelativeLayout的这一点,但是这复杂得多,你需要的。其他答案建议使用网格,这是这里最好的答案,但需要一个不同的方法,以便:
用于限定Grid Rows and Columns列出三种方法的Xamarin.Forms文档(从Xamarin文档复制):
您想要的布局可以通过一个3x3网格来实现,其中中心是自动调整大小 - 即其大小基于内容。然后,PSI标签可以位于同一行中,也可以位于最右侧的列中,因此它们之间的间距不依赖于屏幕大小。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" TextColor="Gray" Text="Healthy" />
<Label Grid.Row="1" Grid.Column="1" Text="62" TextColor="Black" FontAttributes="Bold" FontSize="Large" VerticalOptions="End"/>
<Label Grid.Row="1" Grid.Column="2" Text="PSI" TextColor="Gray" FontSize="Small" VerticalOptions="End" HorizontalOptions="Start"/>
<Image Grid.Row="2" Grid.Column="2" Source="icon.png" VerticalOptions="End" HorizontalOptions="End" Aspect="AspectFit"/>
</Grid>
<Frame CornerRadius="15" HeightRequest="120" WidthRequest="120" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="White">
<Grid Margin="-10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" VerticalTextAlignment="Center" TextColor="Gray" FontSize="17" Text="Healthy"/>
<Label Grid.Row="1" Grid.Column="1" Text="6200" TextColor="Black" FontAttributes="Bold" FontSize="30" VerticalOptions="End" />
<Label Grid.Row="1" Grid.Column="2" Text="PSI" TextColor="Gray" FontSize="Medium" VerticalOptions="End" HorizontalOptions="Start" />
<Image Grid.Row="2" Grid.Column="2" Source="iconHeart.png" VerticalOptions="End" HorizontalOptions="End" Aspect="AspectFit" HeightRequest="30" WidthRequest="30" />
</Grid>
</Frame>
感谢您的回答。但答案与我的期望有所不同。所以在你的口袋里“62PSI”是在父母的中心。但我想要的是“62”只在中心,“PSI”才是正确的。这意味着粗体值应显示在中心。 –
我认为@GeneraleXGR建议一个好方法。你只能从stacklayout中删除PSI laberl并将其设置为Grid.Row =“1”Grid.Column =“2”,并将所有网格设置在固定的宽度和高度框架内(以具有方形控件) –
@AlessandroCaliaro您的建议不是解决方案,因为如果价值的长度太长,它涵盖了“PSI”。 –