[英]Why does extented layout on landscape mode shows half black screen in Xamarin Forms?
我有两个视图和两个内容页面,其中一个我让它们垂直排列,并在设备处于纵向模式时显示,如下所示:
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<views:ScoresView Grid.Row="0"/>
<views:CategoriesView Grid.Row="1"/>
</Grid>
</StackLayout>
以及横向模式的其他内容页面
<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>
这就是我在旋转移动时调用一个或另一个的方式
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)
}
}
您可以更改StackLayout StackOrientation
属性来实现效果。
<StackLayout x:Name="outerStack">
<views:ScoresView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<views:CategoriesView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</StackLayout>
在后面的代码中:
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.