键盘重叠输入字段

时间:2017-10-06 07:51:08

标签: xamarin xamarin.forms keyboard

我有一个视图,其中包含保存在scrollView中的输入字段,这里当我点击输入字段键盘弹出并覆盖其余字段时,按照this我无法解决我的问题。我chnged my主要活动为[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>

1 个答案:

答案 0 :(得分:1)

我相信你有注册形式的情况。为什么不将tableview与Intent="Form"一起使用,因为表视图有一个内置的滚动条,可以适应保持入口视图的行为。它还提供了表单的原生外观。

我在我的一个项目中使用它,它在iOS和Android上都运行良好。

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

参考:TableView

希望这有帮助