Xamarin表单键盘重叠输入字段

时间:2018-04-26 08:45:36

标签: xamarin.forms

我想在键盘打开时滚动页面。现在键盘覆盖了我的其他输入字段。 我尝试过软输入法。但它没有以xamarin的形式工作。

我该怎么办?

1 个答案:

答案 0 :(得分:2)

您必须在条目焦点上添加手动翻译。在构造函数中尝试以下代码:

 this.entryname.Focused += (s, e) => { SetLayoutPosition(onFocus: true); };
 this.entryname.Unfocused += (s, e) => { SetLayoutPosition(onFocus: false); };

然后粘贴下面的方法:

void SetLayoutPosition(bool onFocus)
    {
        if (onFocus)
        {
            if (Device.RuntimePlatform == Device.iOS)
            {
                this.CenteredStackLayout.TranslateTo(0, -100, 50);
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                this.CenteredStackLayout.TranslateTo(0, -100, 50);
            }
        }
        else
        {
            if (Device.RuntimePlatform == Device.iOS)
            {
                this.CenteredStackLayout.TranslateTo(0, 0, 50);
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                this.CenteredStackLayout.TranslateTo(0, 0, 50);
            }
        }
    }

您可以根据需要将“50”更改为任何值。

相关问题