0
當使用Xamarin時,處理方向變化的最佳或最可接受的方法是什麼?在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);
}
}
}