【问题标题】:Scroll to the bottom with opened keyboard and adjustPan使用打开的键盘滚动到底部并调整平移
【发布时间】:2017-04-17 19:14:44
【问题描述】:

当 windowSoftInputMode="adjustPan" 时键盘覆盖按钮时,是否可以滚动到与布局底部对齐的按钮?

我不想使用 windowSoftInputMode="adjustResize" 因为我希望按钮位于键盘下方,并且我想在打开键盘时滚动到按钮。

示例布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />

    </LinearLayout>

</ScrollView>

<Button
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:text="button" />

</RelativeLayout>

我需要滚动到键盘下方的按钮:

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    试试这个添加android.support.v4.widget.NestedScrollView而不是Relativelayout并使android:transcriptMode="alwaysScroll"总是滚动

    <android.support.v4.widget.NestedScrollView     
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:transcriptMode="alwaysScroll">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />
        <Button
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:layout_alignParentBottom="true"
              android:text="button" />
          </LinearLayout>
        </ScrollView>
     </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      相关资源
      最近更新 更多