XAML 在xamarin.forms中,当键盘打开时,如何在网格布局中滚动页面?

acruukt9  于 2023-11-14  发布在  其他
关注(0)|答案(2)|浏览(125)

我在xamarin. forms中面临一个问题。我使用GridView进行登录页面设计,因此可以相应地更改设备高度和宽度。我不想滚动该页面,所以我没有放置任何ScrollView。
XAML设计代码:-

<?xml version="1.0" encoding="utf-8" ?>
<custom:KeyboardResizingAwareContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="HRMS.Login.LoginPage"
             BackgroundImage="login_bg.png"
                   xmlns:local="clr-namespace:HRMS;assembly=HRMS"
                   Title="{x:Static local:AppResources.TitleLogin}"
             xmlns:custom="clr-namespace:HRMS.Login;assembly=HRMS">
  <ContentPage.Padding>
    <OnIdiom x:TypeArguments="Thickness" Phone="60,40,60,40" Tablet="120,100,120,100" />
  </ContentPage.Padding>
  <custom:KeyboardResizingAwareContentPage.Resources>
    <ResourceDictionary>
      <Style x:Key="SubTitleStyle" TargetType="Label">
        <Setter Property="FontSize" Value="Small" />
        <Setter Property="FontAttributes" Value="Bold" />
        <Setter Property="TextColor" Value="White" />
      </Style>
    </ResourceDictionary>
  </custom:KeyboardResizingAwareContentPage.Resources>
  <custom:KeyboardResizingAwareContentPage.Content>
    <AbsoluteLayout x:Name="AbsMain">
      <Grid VerticalOptions="Center" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
        <Grid.RowDefinitions>
          <RowDefinition Height="35*"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="6*"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="6*"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Image x:Name="ImgLogo" Source="login_logo.png" HorizontalOptions="Center" Grid.Row="0"/>
        <StackLayout Grid.Row="1">
          <StackLayout.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double" Tablet="55" Phone="35" />
          </StackLayout.HeightRequest>
        </StackLayout>
        <Frame OutlineColor="#DCDCDC"
            HorizontalOptions="FillAndExpand" VerticalOptions="Center"
            HasShadow="false" Padding="1"
            Grid.Row="2"
            BackgroundColor="White"
            Margin="5,0,5,0">
          <Frame.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double" Tablet="55" Phone="35" />
          </Frame.HeightRequest>
          <Frame.Content>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="9*"/>
              </Grid.ColumnDefinitions>
              <Image x:Name="ImgLoginName" Grid.Column="0" Source="ico_login_name.png"
                  HorizontalOptions="StartAndExpand" VerticalOptions="Center" Margin="5,0,0,0"/>
              <StackLayout Grid.Column="1" VerticalOptions="Center">
                <Entry x:Name="TxtUsername" TextColor="#f15a23"
                       Margin="5,0,0,0"
                       PlaceholderColor="#8c8c8c"
                       BackgroundColor="White"
                       Placeholder="{x:Static local:AppResources.PHEmployeeCode}" />
              </StackLayout>
            </Grid>
          </Frame.Content>
        </Frame>
        <Frame OutlineColor="#DCDCDC"
            HorizontalOptions="FillAndExpand" VerticalOptions="Center"
            HasShadow="false" Padding="1"
            Grid.Row="3"
            BackgroundColor="White"
            Margin="5,0,5,0">
          <Frame.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double" Tablet="55" Phone="35" />
          </Frame.HeightRequest>
          <Frame.Content>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="9*"/>
              </Grid.ColumnDefinitions>
              <Image x:Name="ImgLoginPassword" Grid.Column="0" Source="ico_login_password.png"
                  HorizontalOptions="StartAndExpand" VerticalOptions="Center" Margin="5,0,0,0"/>
              <StackLayout Grid.Column="1" VerticalOptions="Center">
                <Entry x:Name="TxtPassword" IsPassword="True" TextColor="#f15a23"
                     PlaceholderColor="#8c8c8c"
                     Margin="5,0,0,0"
                     BackgroundColor="White"
                     Placeholder="{x:Static local:AppResources.PHPassword}" />
              </StackLayout>
            </Grid>
          </Frame.Content>
        </Frame>
        <Label x:Name="LblForgotPassword" Grid.Row="4" Margin="5,0,5,0"
                    Text="Forgot Password?" TextColor="Black" HorizontalTextAlignment="End"/>
        <Button x:Name="BtnLogin" Text="{x:Static local:AppResources.BLogin}" Clicked="LoginButton_Clicked"
                  Grid.Row="5" BackgroundColor="#f15a23" TextColor="White"
                  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
          <Button.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double" Tablet="55" Phone="45" />
          </Button.HeightRequest>
        </Button>
        <Image x:Name="ImgOr" Grid.Row="6" HorizontalOptions="FillAndExpand"
               Source="or.png" />
        <Button x:Name="BtnUpdateDevicewithlogin" Text="{x:Static local:AppResources.BUpdateDevice}"
                Clicked="UpdateDeviceWithLoginButton_Clicked" Grid.Row="7"
                BackgroundColor="#f15a23" TextColor="White" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
          <Button.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double" Tablet="55" Phone="45" />
          </Button.HeightRequest>
        </Button>
      </Grid>
      <ActivityIndicator x:Name="actIndicator2" Color="#f15a23" Opacity="2"
              HeightRequest="50" WidthRequest="50" VerticalOptions="Center" HorizontalOptions="Center"
              AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" />

    </AbsoluteLayout>

  </custom:KeyboardResizingAwareContentPage.Content>
</custom:KeyboardResizingAwareContentPage>

字符串
x1c 0d1x的数据



我使用“KeyboardResizingAwareContentPage”页面,而不是“ContentPage”,因为在iOS的页面是不设置时,键盘是打开的。密码字段隐藏在键盘后面,所以用户不能看到什么,然后键入。这就是为什么我使用渲染的内容页在IO。

如上图,当我专注于用户名或密码输入字段时,两个按钮隐藏在键盘后面。客户端要求是,在那个时候页面应该滚动。我如何解决这个问题?通过渲染可能吗?我在两个平台中都面临这个问题。(iOS和Android)

cotxawn7

cotxawn71#

即使你不想滚动你的页面,也可以使用ScrollView作为你的页面的根,并把你的网格放在里面。
这个应该能修好

eblbsuwk

eblbsuwk2#

您可以通过使用Android平台特定的功能来解决此问题,该功能用于配置软键盘输入区域的操作模式。在XAML中,您可以通过将WindowSoftInputModeAdjust枚举中的值分配给Application.WindowSoftInputModeAdjust附加属性来应用它。

<Application ...
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
             android:Application.WindowSoftInputModeAdjust="Resize">
  ...
</Application>

字符串

相关问题