软键盘显示/隐藏时,ScrollView中的布局更新不正确

时间:2017-05-22 11:51:06

标签: android xamarin.forms soft-keyboard

我有一个简单的布局,包括Entry和Button。目标是将Button置于底部,将Entry置于剩余空间的中心。一切都在开始。这是布局和截图。

FormsAppCompatActivity

enter image description here

我还设置了WindowSoftInputMode以在Android项目中调整大小(在代码中,考虑到Xamarin.Forms中的错误,当使用 protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); //https://bugzilla.xamarin.com/show_bug.cgi?id=39765 App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize); //https://bugzilla.xamarin.com/show_bug.cgi?id=39765 //Remove the status bar underlay in API 21+ if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Window.DecorView.SystemUiVisibility = 0; var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); statusBarHeightInfo?.SetValue(this, 0); Window.SetStatusBarColor(Android.Graphics.Color.Black); } } 时在清单中设置标记时将其重置为平移

Bounds

当Entry获得焦点时,页面不会调整大小(虽然当软键盘可见时我可以滚动到最底部)

enter image description here

当软键盘隐藏时,内容调整不正确,并且只占据屏幕的一部分。enter image description here

在软键盘变为可见/不可见之前,看起来布局过程是基于边界执行的。但是,似乎ScrollView的所有ContentSize属性(Page,ScrollView和StackLayout)以及ForceLayout()属性都具有正确的数值(我在按钮单击处理程序中跟踪它们)。我试图在同一个按钮点击处理程序中调用 <asp:TextBox ID="From_Date_Txt" runat="server" CssClass="form-control"></asp:TextBox> <asp:TextBox ID="Date_To_Txt" runat="server" CssClass="form-control"></asp:TextBox> 不同的元素,但没有运气。

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我确实认为FillAndExpand的{​​{1}}是如何设计的,它是为 从父布局沿Y轴有多余空间时的元素布局。如果布局的多个子项设置为展开,则额外的空间按比例分配。

由于你没有任何固定大小,当键盘消失时,布局会调整大小,我猜VerticalOptions将首先测量沿轴有多少额外空间,然后分配空间儿童。

解决问题的一个非常简单的解决方法是为FillAndExpand提供固定的尺寸,但是您说

  

目标是将Button置于底部,将Entry置于剩余空间的中心。

如果您想在此处保留原始尺寸,可以在出现时将高度设置为StackLayout,意味着覆盖后面代码中的StackLayout方法,例如:

OnAppearing()