代码之家  ›  专栏  ›  技术社区  ›  justdan0227

Android ScrollView,在软键盘上的操作栏下

  •  2
  • justdan0227  · 技术社区  · 9 年前

    我已经阅读了一些关于这个问题的讨论,它与 android:windowSoftInputMode="stateHidden|adjustResize" (以及adjustPan)。

    我有一个布局,在包含10个LinearLayout部分(TextView/EditText视图)的ScrollView中有一个LinearLayout。我试过我读过的每一种组合,无论怎样,当键盘因点击顶部EditText而打开时,视图都会调整(平移),使顶部字段位于操作栏后面。我可以滚动到页面的底部,但我无法到达顶部的EditText-我只能滚动到第二个。我可以试着向下拉,我可以开始看到顶部的EditText,但除非我取消键盘,否则无法显示它(很明显,我无法编辑文本)。

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.example.myproject.FirstActivity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView"
        tools:showIn="@layout/activity_work"
        android:layout_gravity="center_horizontal">
    
      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="x1"
                android:layout_weight="50"/>
    
            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:ems="10"
                android:id="@+id/work_one"
                android:hint="0"
                android:gravity="right"
                android:selectAllOnFocus="true"
                android:textAlignment="gravity"
                android:layout_weight="50" />
        </LinearLayout>
        .
        . (9 more of these)
        .
      </LinearLayout>
    </ScrollView>
    

    更新:

    所以我尝试了:android:windowSoftInputMode=“adjustResize”和/或android:windowSoftInputMode=“adjstPan”,软键盘会移动操作栏下的顶部字段。

    思想?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Community Mohan Dere    8 年前

    尝试android:windowSoftInputMode=“adjustResize”或android:windowSoftInputMode=“adjstPan”

    doc

    “调整大小”

    活动的主窗口总是调整大小,以便为屏幕上的软键盘腾出空间。

    “调整平移”

    活动的主窗口没有调整大小以为软键盘腾出空间。相反,窗口的内容会自动平移,这样当前焦点就不会被键盘遮挡,用户可以随时看到他们正在键入的内容。这通常比调整大小更不可取,因为用户可能需要关闭软键盘才能接触到窗口中被遮挡的部分并与之交互。

    我抄了答案 this Stack Overflow answer