[Xamarin.Forms 2.5.0.91635] [Android 5,6,7,8]
我有一个页面,其中有一个 ListView ,其中包含一个输入条目和一个标签。我的问题是,在 Android 中,点击第一个或第二个条目时,会出现键盘。我希望它向下滚动页面以选择最后一个条目,但我看不到(或聚焦)最后一个条目,因为它被软键盘重叠了。当软键盘启用/可见时,我无法滚动到最后一个条目,因为软键盘隐藏了最后一个条目。 当我隐藏/禁用软键盘时,我可以滚动到最后一个条目,但我不想要这个!
我在互联网上搜索并尝试了很多,但没有任何效果。
无效的解决方案: https://gist.github.com/jimmgarrido/e36033b26f01e8da091fd321d41d991a xamarinformscorner.blogspot.nl/2016/06/soft-keyboard-hiding-entries-fields-in.html https://forums.xamarin.com/discussion/62668/appcompat-does-not-resize-screen-with-keyboard
<ContentPage.Content>
<ScrollView>
<StackLayout x:Name="StackLayoutButtons" HorizontalOptions="Center" Orientation="Horizontal">
<Button x:Name="PreviousButton" WidthRequest="35" FontSize="23" FontAttributes="Bold" Clicked="PreviousButton_OnClicked"></Button>
<Button x:Name="DatePickerButton" FontSize="20" Clicked="DatePickerButton_OnClicked"></Button>
<DatePicker x:Name="DatePicker" Format="dddd d MMMM yyyy" VerticalOptions="Center" HorizontalOptions="FillAndExpand" IsVisible="False" IsEnabled="False"/>
<Button x:Name="NextButton" WidthRequest="35" FontSize="23" FontAttributes="Bold" Clicked="NextButton_OnClicked"></Button>
<Button x:Name="LastButton" WidthRequest="50" FontSize="23" FontAttributes="Bold" Clicked="LastButton_OnClicked"></Button>
</StackLayout>
<ListView x:Name="ListViewItemPage" ItemTapped="ListView_OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<RelativeLayout x:Name="RelativeLayout" >
<Label x:Name="DescriptionLabel" Text="{Binding Description}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=15}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=15}" />
<Entry x:Name="Entry" WidthRequest="85" Keyboard="Text" HorizontalTextAlignment="Start" FontSize="19" HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding Value, Mode=TwoWay, Converter={StaticResource FloatValueConverter}}" Unfocused="ValueEntry_OnUnfocused"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=10}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant={StaticResource ConstantMultiPlatform}}" >
<Entry.HeightRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS" Value="28"></On>
<On Platform="Android" Value="42"></On>
<On Platform="UWP" Value="32"></On>
</OnPlatform>
</Entry.HeightRequest>
</Entry>
</RelativeLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ScrollView>
</ContentPage.Content>
也许这里有人有针对此错误的有效解决方案/解决方法?
最佳答案
这是一个众所周知的问题,由于 Xamarin Forms 上的错误而发生。
将 WindowSoftInputMode 属性设置为 Activity 本身并不能完全正常工作,因为存在错误,因此您必须通过在
下面添加这行代码来显式设置此属性LoadApplication(new App());
调用:
Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
https://stackoverflow.com/questions/47530634/