【发布时间】:2020-02-15 05:52:44
【问题描述】:
我在 Xamarin.Forms 中正确缩放容器高度和字体大小时遇到问题。
1) 第一个问题是我需要在我的一个容器中设置静态高度,但它在不同的设备上看起来不同。我不确切知道,但假设这个问题可能是由屏幕密度引起的。我应该以某种方式缩放容器的高度还是 Xamarin.Forms 应该为我处理这个?
2) 第二个问题是我需要设置正确的跨平台字体。有没有办法让 Xamarin.Forms 为我处理它,或者我需要使用 Device.RuntimePlatform 属性来设置它?也如这里所说:https://docs.microsoft.com/pl-pl/xamarin/xamarin-forms/user-interface/text/fonts - 命名字体大小不是可接受的解决方案。对于 iPod 我需要使用 micro,但在 android 上几乎看不到文字。
在模拟器上发生了许多奇怪的事情,顶部栏超出了比例,整个外观被放大了。这是我的错还是 Xamarin 不是我认为的通用平台?
这是我页面的代码:
<StackLayout>
<SearchBar
VerticalOptions="Start"
TextChanged="SearchBar_OnTextChanged"
PlaceholderColor="#C0C0C0"></SearchBar>
<ListView
BackgroundColor="#f2f2f2"
VerticalOptions="Center"
ItemTapped="SelectProcedure"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell
Text="{Binding Name}"
TextColor="Black"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout
BackgroundColor="White"
HeightRequest="80"
HorizontalOptions="FillAndExpand"
VerticalOptions="EndAndExpand">
<Grid
Padding="10,5,10,5"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
VerticalTextAlignment="Center"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
TextColor="Black"/>
<telerikInput:RadButton
Grid.Column="1"
Grid.Row="0"
Padding="5,0,5,0"
ImageSource="plus.png"/>
</Grid>
</StackLayout>
</StackLayout>
这是我拥有的两个设备和模拟器的屏幕截图:
Android 8.1
iPod touch 6
Android 8.1(模拟器)
【问题讨论】:
-
您是否尝试过使用 PositionProportional 标志的 AbsoluteLayout 将按钮控件设置在底部而不是网格?此外,尝试新的“视觉”属性以获得跨平台和设备的更统一的结果。
标签: xamarin.forms xamarin.android xamarin.ios