【发布时间】:2018-10-17 01:15:44
【问题描述】:
鉴于不同的屏幕尺寸,缩放 UI 的可接受方法是什么?
在设置 UI 时,它在一个屏幕上看起来很棒,但在另一个屏幕上却很糟糕。尝试根据屏幕尺寸设置可能的动态样式。我在这里有一个简单的标题,标签中有一个 FormattedString。我想将整个标签居中,跨度格式保持不变。理想情况下,我想将文本的高度设置为 Current.MainPage.Height 的某个百分比 ...
来自 App.xaml
<Application.Resources>
<ResourceDictionary>
<Style x:Key="HeaderSpans" TargetType="Span" >
<Setter Property="BackgroundColor" Value="Transparent"></Setter>
<Setter Property="HorizontalOptions" Value="Center"></Setter>
<Setter Property="TextColor" Value="White"></Setter>
<Setter Property="VerticalTextAlignment" Value="Center"></Setter>
<Setter Property="Margin" Value="0, 20, 0, 0"></Setter>
</Style>
<Style x:Key="HeaderSpan" TargetType="Span" >
<Setter Property="TextColor" Value="White"></Setter>
<Setter Property="FontSize" Value="32"></Setter>
</Style>
<Style x:Key="HeaderSpanB" TargetType="Span" >
<Setter Property="TextColor" Value="White"></Setter>
<Setter Property="FontSize" Value="32"></Setter>
<Setter Property="FontAttributes" Value="Bold"></Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
背后的代码
switch (Device.RuntimePlatform)
{
case Device.iOS:
//MainPage.BackgroundColor = Color.Black;
break;
case Device.Android:
//MainPage.BackgroundColor = Color.Red;
break;
case Device.UWP:
//MainPage.BackgroundColor = Color.Orange;
break;
default:
//MainPage.BackgroundColor = Color.Transparent;
break;
}
我想我也许可以利用这段代码来做这件事。但我不知道如何从那里影响风格。我认为二传手可能是正确的道路。我还没有取得实质性的进展。
来自 Header.xaml
<!-- dark-blue backing header -->
<Image Source="Header752x135.png" VerticalOptions="Start" HorizontalOptions="CenterAndExpand"></Image>
<!-- SHIPSHAPE text placed on the backing header -->
<Label
Style="{StaticResource HeaderSpans}"
>
<Label.FormattedText>
<FormattedString>
<Span Text="SHIP" Style="{StaticResource HeaderSpan}" />
<Span Text="SHAPE" Style="{StaticResource HeaderSpanB}" />
</FormattedString>
</Label.FormattedText>
</Label>
后面没有代码。
如果有人能引导我找到正确的解决方案,我将不胜感激。
【问题讨论】:
标签: c# xaml xamarin.forms