我有一個由Entry和Button組成的簡單佈局。目標是將Button放置在底部,並將Entry放置在剩餘空間的中心。一切工作在開始。這裏是佈局和截圖。當軟鍵盤顯示/隱藏時,ScrollView中的佈局更新不正確
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.HasNavigationBar="False"
x:Class="ParentAdda.Pages.Test">
<ScrollView x:Name="Qq" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout x:Name="Ww" Orientation="Vertical" VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<BoxView VerticalOptions="FillAndExpand" HeightRequest="0" BackgroundColor="Aquamarine" />
<Entry
FontSize="Medium"
Placeholder="+111111111"
HorizontalOptions="FillAndExpand"
Keyboard="Telephone" />
<BoxView VerticalOptions="FillAndExpand" HeightRequest="0" BackgroundColor="Coral" />
<Button Text="Update" Clicked="Button_OnClicked"
HorizontalOptions="Fill"
BorderRadius="20"
BackgroundColor="Lime"
TextColor="White"
FontSize="Large"
FontAttributes="Bold" />
</StackLayout>
</ScrollView>
</ContentPage>
我也設置WindowSoftInputMode在Android項目來調整(代碼中,考慮到Xamarin.Forms的bug當標籤被重置使用FormsAppCompatActivity
時清單當設置爲潘)
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
特性(頁,滾動型和StackLayout)以及滾動型的ContentSize
酒店有正確的數值(我跟蹤他們在按鈕按下的處理程序)。我試圖在相同的按鈕點擊處理程序中的不同元素上調用ForceLayout()
,但沒有運氣。
有誰知道如何解決這個問題?