1

在我的应用程序配置文件页面中,我水平显示了一些按钮,它在 iPhone 7 中看起来不错,但在 iPhone 5 中,由于屏幕尺寸小,按钮看起来并不好。我想让按钮的布局在小屏幕上垂直对齐。请参阅以下示例代码。

`

<App Background="#eeef">
  <Fuse.iOS.StatusBarConfig ux:Name="statusBarConfig" Style="Dark"/>
    <StackPanel ux:Name="textPanel" Alignment="Center">
      <Text ux:Class="TitleText" Color="#000" TextAlignment="Center" Padding="2"/>
      <TitleText ux:Name="topText">This is a long text aligned horizontally</TitleText>
      <TitleText ux:Name="bottomText">This is a another long text</TitleText>
    </StackPanel>
</App>

`

这两个文本在所有屏幕中水平对齐。我怎样才能让它在小屏幕上自动垂直对齐?

4

1 回答 1

2

正如我们发现的那样,您的问题实际上是关于更改 的堆叠方向,而StackPanel不是关于对齐。

为此,您需要使用WhileWindowSizeWhileWindowPortrait/等触发器WhileWindowLandscape响应式布局文档中对此进行了很好的解释。

这是一个示例应用程序,可以满足您的需求:

<App>
    <Text ux:Class="TitleText" Color="#000" TextAlignment="Center" Padding="2"/>
    <!-- create a new trigger shorthand for when we are running on a "big screen" -->
    <WhileWindowSize ux:Class="WhileBigScreen" GreaterThan="599,1" />

    <!-- by default (on small screens in portrait), stack things vertically -->
    <StackPanel ux:Name="textPanel" Alignment="Center">
        <TitleText ux:Name="topText">This is a long text aligned horizontally</TitleText>
        <TitleText ux:Name="bottomText">This is a another long text</TitleText>
    </StackPanel>

    <!-- when running on a big screen, stack things horizontally disregarding what the device orientation is -->
    <WhileBigScreen>
        <Change textPanel.Orientation="Horizontal" />
    </WhileBigScreen>
    <!-- when running on a small screen, only stack things horizontally when in landscape -->
    <WhileBigScreen Invert="true">
        <WhileWindowLandscape>
            <Change textPanel.Orientation="Horizontal" />
        </WhileWindowLandscape>
    </WhileBigScreen>
</App>
于 2017-09-28T09:18:45.837 回答