Him*_*edi 6 xaml xamarin.forms
我正在使用xamarin表格.我在xaml中设计了一个登录表单页面.我想在键盘出现时向上移动登录表单视图,以便在平台Android和平台的情况下都可以看到文本字段和登录按钮IOS.如何通过动态计算键盘高度来计算键盘高度并向上移动登录表单视图.
下面是我的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>
Run Code Online (Sandbox Code Playgroud)
我不想执行任何类型的页面自定义呈现.是否有任何资源可以通过它编写依赖服务来计算不同移动视图跨平台的键盘高度.我经历过这个,但它有一些我不想要的自定义渲染.
选项1:
Android:将此添加到您的清单:
<activity //Your MainActivity
android:windowSoftInputMode="stateVisible|adjustResize" ... >
...
</activity>
Run Code Online (Sandbox Code Playgroud)
Ios:添加此nuget包:https://www.nuget.org/packages/Xam.Plugins.Forms.KeyboardOverlap/
并初始化它:
Xamarin.Forms.Init();//platform specific init
KeyboardOverlapRenderer.Init ();
Run Code Online (Sandbox Code Playgroud)
选项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));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6267 次 |
| 最近记录: |