gpt4 book ai didi

xaml - xamarin 形式 : Move the view Upward according to keyboard height

转载 作者:行者123 更新时间:2023-12-03 00:45:30 26 4
gpt4 key购买 nike

我正在使用 xamarin 表单。我用xaml设计了一个登录表单页面。我想在键盘出现时向上移动登录表单 View ,以便在平台 AndroidIOS 上都可以看到文本字段和登录按钮。如何计算键盘高度并通过动态计算键盘高度将登录表单 View 向上移动。

enter image description here

下面是我的 xaml 代码:

<ContentPage>
<ScrollView>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid Padding="20, 30, 20, 20" RowSpacing="20" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Image Grid.Row="0" Source="login.png" HorizontalOptions="Center" VerticalOptions="Center"/>

<Entry Grid.Row="2" x:Name="entryUserName" HorizontalOptions="Fill" Placeholder="Username" PlaceholderColor="#707070" Text="{Binding UserName,Mode=TwoWay}" Margin="5"/>

<BoxView Grid.Row="2" HeightRequest="1" HorizontalOptions="Fill" BackgroundColor="#707070" VerticalOptions="End"/>

<Entry Grid.Row="3" x:Name="entryPassword" Text="{Binding Password,Mode=TwoWay}" Placeholder="Password" PlaceholderColor="#707070" Margin="5" HorizontalOptions="Fill" IsPassword="True"/>

<BoxView Grid.Row="3" HeightRequest="1" HorizontalOptions="Fill" BackgroundColor="#707070" VerticalOptions="End"/>

<Button Grid.Row="5" HorizontalOptions="Center" VerticalOptions="Center" Text="Login" Command="{Binding doLoginCommand}" CommandParameter="entryUserName,entryPassword" />

</Grid>
</AbsoluteLayout>
</ScrollView>
</ContentPage>

我不想对页面执行任何类型的自定义呈现。是否有任何资源可以通过它编写依赖服务来计算不同移动 View 跨平台的键盘高度。我经历过this但它有某种我不想要的自定义渲染。

最佳答案

选项 1:

安卓:将其添加到您的 list 中:

<activity //Your MainActivity
android:windowSoftInputMode="stateVisible|adjustResize" ... >
...
</activity>

IOS:添加这个 nuget 包: https://www.nuget.org/packages/Xam.Plugins.Forms.KeyboardOverlap/

并初始化它:

Xamarin.Forms.Init();//platform specific init
KeyboardOverlapRenderer.Init ();

选项 2:

将此代码添加到您的 Page 类中:

        protected override void OnAppearing()
{
base.OnAppearing();
entryUserName.Focused += InputFocused;
entryPassword.Focused += InputFocused;
entryUserName.Unfocused += InputUnfocused;
entryPassword.Unfocused += InputUnfocused;
}

protected override void OnDisappearing()
{
base.OnDisappearing();
entryUserName.Focused -= InputFocused;
entryPassword.Focused -= InputFocused;
entryUserName.Unfocused -= InputUnfocused;
entryPassword.Unfocused -= InputUnfocused;
}
void InputFocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,-360, Content.Bounds.Width, Content.Bounds.Height));
}

void InputUnfocused(object sender, EventArgs args){
Content.LayoutTo(new Rectangle(0,0, Content.Bounds.Width, Content.Bounds.Height));
}

关于xaml - xamarin 形式 : Move the view Upward according to keyboard height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39641429/

26 4 0
文章推荐: css - 如何并排放置两个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com