在我的应用资料页面中,我水平显示了一些按钮,它在iPhone 7中看起来不错,但是当涉及到iPhone 5时,由于屏幕尺寸较小,按钮看起来不太好。我想让按钮的布局在小屏幕上垂直对齐。请参阅以下示例代码。
`
constructor(router:Router) {
router.events.forEach((event) => {
if(event instanceof NavigationStart) {
}
// NavigationEnd
// NavigationCancel
// NavigationError
// RoutesRecognized
});
}
`
这两个文本在所有屏幕中水平对齐。如何让它在小屏幕上自动垂直对齐?
答案 0 :(得分:2)
正如我们发现的那样,您的问题实际上是关于更改StackPanel
的堆叠方向,而不是关于对齐。
要实现这一目标,您需要使用WhileWindowSize
和WhileWindowPortrait
/ WhileWindowLandscape
等触发器。在Responsive layout docs中已经很好地解释了这一点。
这是一个示例应用程序,可以满足您的需求:
<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>