[英]Why does extented layout on landscape mode shows half black screen in Xamarin Forms?
I have two Views and two content pages, in one I have them arrange vertically and it's shown when the device is on portrait mode, something like this:我有两个视图和两个内容页面,其中一个我让它们垂直排列,并在设备处于纵向模式时显示,如下所示:
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<views:ScoresView Grid.Row="0"/>
<views:CategoriesView Grid.Row="1"/>
</Grid>
</StackLayout>
And the other content page for landscape mode以及横向模式的其他内容页面
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<views:ScoresView Grid.Column="0"/>
<views:CategoriesView Grid.Column="1"/>
</Grid>
</StackLayout>
I wanted it to look like this:我希望它看起来像这样:
This is how I'm calling one or the other when the rotation is shifted这就是我在旋转移动时调用一个或另一个的方式
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width > height)
{
//device is landscape
App.Current.MainPage = new CategoriesLands();
}
else
{
//device is portrait (or square)
}
}
You could change the StackLayout StackOrientation
property to achieve the effect.您可以更改StackLayout StackOrientation
属性来实现效果。
<StackLayout x:Name="outerStack">
<views:ScoresView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<views:CategoriesView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</StackLayout>
in the behind code:在后面的代码中:
private double width;
private double height;
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width != this.width || height != this.height)
{
this.width = width;
this.height = height;
if (width > height)
{
outerStack.Orientation = StackOrientation.Horizontal;
}
else
{
outerStack.Orientation = StackOrientation.Vertical;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.