我在尝试编写一个 Xamarin.Forms 聊天应用程序。问题是:在 Android 上,一旦键盘弹出,整个页面(包括 ActionBar)都会向上移动。我已经通过使用一个 NuGet 包来调整页面大小,在 IOS 上解决了这个问题。
我已经在 Android 项目的 MainActivity.cs 中设置了
有人之前遇到过同样的问题吗?是否有一个适用于所有支持平台的官方 Xamarin.Forms 解决方案?
这是目前我的聊天布局:
我已经在 Android 项目的 MainActivity.cs 中设置了
WindowSoftInputMode = Android.Views.SoftInput.AdjustResize
,但它没有起作用。我还尝试通过重新计算屏幕大小手动调整页面大小,但我还没有找到在不同设备上精确计算键盘大小的解决方案。有人之前遇到过同样的问题吗?是否有一个适用于所有支持平台的官方 Xamarin.Forms 解决方案?
这是目前我的聊天布局:
<ContentPage.Content>
<StackLayout Padding="0">
<ScrollView>
<ListView HasUnevenRows="true" x:Name="lvChat" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill" Padding="5">
<Label Text="{Binding Author, StringFormat='{0}: '}" TextColor="Navy" FontSize="14" />
<Label Text="{Binding Text}" TextColor="Black" FontSize="15" />
<Label Text="{Binding Time}" TextColor="Black" FontSize="14" />
<!-- Format for time.. , StringFormat='{0:HH:mm}' -->
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
<StackLayout Orientation="Horizontal" Padding="0" Margin="5, 5, 5, 5">
<Entry Keyboard="Chat" x:Name="tbxChatInput" HorizontalOptions="FillAndExpand" Placeholder="Send a Message..." />
<Button x:Name="btnSendMsg" HorizontalOptions="End" Text="Send" Margin="5"/>
</StackLayout>
</StackLayout>
提前感谢您!