【发布时间】:2017-06-27 09:50:49
【问题描述】:
在使用 Xamarin 时,处理方向变化的最佳或最被接受的方法是什么?
我有一个轮播页面,它在 5 个内容页面中旋转(同一页面,只是不同的文本/图像),在内容页面中我有一个 6 行网格,每行包含一个图像、文本或一个按钮。
当从纵向更改为横向时,我会在 OnSizeAllocated 中重置它们的大小和填充。这似乎对 5 个内容页面中的 3 个随机起作用,另外 2 个中的文本将不在位置,而且并不总是相同的 3 个起作用。
我猜有比手动调整大小更好的方法吗?
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height); //must be called
if (this.width != width || this.height != height)
{
this.width = width;
this.height = height;
//reconfigure layout
if (width > height)
{
img.HeightRequest = 62.5;
img.WidthRequest = 62.5;
logo.HeightRequest = 52.5;
logo.WidthRequest = 142.27;
headerStack.Padding = new Thickness(0, -60, 0, 0);
txtStack.Padding = new Thickness(20, -60, 20, 0);
sIndicator.Padding = new Thickness(20, 0, 20, 100);
sButton.Padding = new Thickness(0, -40, 0, 0);
}
else
{
img.WidthRequest = 250;
img.HeightRequest = 250;
logo.HeightRequest = 70;
logo.WidthRequest = 189.7;
headerStack.Padding = new Thickness(20, 40, 20, 0);
txtStack.Padding = new Thickness(20, 0, 20, 0);
sIndicator.Padding = new Thickness(20, 25, 20, 0);
}
}
}
【问题讨论】:
标签: xamarin screen-orientation