【问题标题】:Keyboard overlapping the entry fields键盘与输入字段重叠
【发布时间】:2017-10-06 16:56:00
【问题描述】:

我有一个视图,其中包含保存在滚动视图中的输入字段,当我点击输入字段时,键盘弹出并覆盖其余字段,通过关注 this 我无法解决我的问题。我改变了我的主要活动作为[Activity(Label = "MyApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, WindowSoftInputMode = SoftInput.AdjustResize)] 并且还检查了AdjustPan 没有任何效果,当键盘弹出时如何将这些字段滚动到最后一个字段?

<ContentView>
<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>
  <ScrollView Orientation="Vertical">
  <StackLayout Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" Padding="10">
    <StackLayout.Spacing>
      <OnIdiom x:TypeArguments ="x:Double" Phone = "8" Tablet ="16"/>
    </StackLayout.Spacing>
    <Entry x:Name="FirstNameEntry" PlaceholderColor="#9E9E9E" Text="{Binding FirstName}" Placeholder="First name" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>         
    </Entry>
    <Entry x:Name="LastNameEntry" Text="{Binding LastName}" PlaceholderColor = "#9E9E9E" Placeholder="Last name" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>         
    </Entry>
    <Entry x:Name="MobileNameEntry" Keyboard="Numeric" PlaceholderColor="#9E9E9E" Text="{Binding MobileNumber}" TextChanged = "On_PhoneNumberTextChanged" Placeholder="Mobile number" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>         
    </Entry>
    <Entry x:Name="HouseNumberEntry" Text="{Binding HouseNumber}" PlaceholderColor="#9E9E9E" Placeholder="House number" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>
    </Entry>
    <Entry x:Name="StreetNameEntry" Text="{Binding StreetName}" PlaceholderColor="#9E9E9E" Placeholder="Street name" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>
    </Entry>
    <Entry x:Name="CityNameEntry" Text="{Binding City}" PlaceholderColor="#9E9E9E" Placeholder="City" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>
    </Entry>
    <Entry x:Name="PostCodeEntry" Text="{Binding PostalCode}" PlaceholderColor="#9E9E9E" Placeholder="Post code" HorizontalOptions="FillAndExpand" TextColor="#191919" FontFamily="Avenir Book">
      <Entry.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Entry.HeightRequest>
    </Entry>
    <Picker x:Name="AddressTypePicker" Title="Select type" HorizontalOptions="FillAndExpand" SelectedIndexChanged="AddressTypePicker_OnSelectedIndexChanged">
      <Picker.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="40" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="45" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
      </Picker.HeightRequest>
    </Picker>
  </StackLayout>
    </ScrollView>
  <StackLayout BackgroundColor="#f2c646" Grid.Row="1" Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="End" Padding="0">
    <StackLayout.HeightRequest>          
      <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="50" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="50" Android="60" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
    </StackLayout.HeightRequest>
    <StackLayout Padding="10">
      <Label Text="Cancel" TextColor="Black" HorizontalOptions="StartAndExpand" FontFamily="Avenir Book" VerticalTextAlignment="Center">
        <Label.GestureRecognizers>
          <TapGestureRecognizer Tapped="OnCancelBtnClicked"/>
        </Label.GestureRecognizers>
        <Label.FontSize>              
          <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="15" Android="17" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="20" Android="22" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
        </Label.FontSize>
      </Label>
    </StackLayout>
    <StackLayout HorizontalOptions="EndAndExpand" Padding="10">
      <Label Text="Save" TextColor="Black" VerticalTextAlignment="Center" FontFamily="Avenir Book">
        <Label.GestureRecognizers>
          <TapGestureRecognizer Command="{Binding SaveCommand}"/>
        </Label.GestureRecognizers>
        <Label.FontSize>
          <OnIdiom x:TypeArguments="x:Double">
          <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="15" Android="17" WinPhone="28" />
          </OnIdiom.Phone>
          <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="20" Android="22" WinPhone="28" />
          </OnIdiom.Tablet>
        </OnIdiom>
        </Label.FontSize>
      </Label>
    </StackLayout>
  </StackLayout>
</Grid>

【问题讨论】:

    标签: xamarin xamarin.forms keyboard


    【解决方案1】:

    我相信你有一个注册表单的情况。为什么不使用带有Intent="Form" 的tableview,因为tableview 有一个内置的滚动条,可以适应keep-entry-in-view 行为。它还提供了表单的原生外观。

    我在我的一个项目中使用了它,它在 iOS 和 Android 上都能完美运行。

    <TableView Intent="Form" HasUnevenRows="true">
    </TableView>
    

    参考:TableView

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2011-02-27
      相关资源
      最近更新 更多