首页 文章

处理Xamarin中的页面方向更改

提问于
浏览
0

使用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);
                }
            }
        }

1 回答

  • 0

    通过对我设置的一些调整,我得到了很好的工作,仍然会对其他人对他们如何做的看法感兴趣 .

相关问题