這裏是我想在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」。 –