2017-06-27 21 views
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); 
       } 
      } 
     } 

回答

0

有了一些调整了我的设置,我得到这个工作得很好,仍然有兴趣在其他人的意见,他们是如何做到这一点。