【问题标题】:Android ScrollView, under Action Bar on SoftkeyboardAndroid ScrollView,在软键盘上的操作栏下
【发布时间】:2016-03-10 17:57:10
【问题描述】:

我已经阅读了有关此问题的多个讨论,当尝试获取 LinearLayout 的 ScrollView 以在显示键盘时进行调整时,它与清单文件的 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="adjustPan" 并且软键盘会移动操作栏下方的顶部字段。

想法?

【问题讨论】:

  • 嘿,我也面临同样的问题。你解决过这个问题吗?

标签: android android-layout android-scrollview


【解决方案1】:

尝试 android:windowSoftInputMode="adjustResize" 或 android:windowSoftInputMode="adjustPan"

来自doc

“调整大小”

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

“调整盘”

Activity 的主窗口没有调整大小来为软键盘腾出空间。相反,窗口的内容会自动平移,因此当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

我从this Stack Overflow answer复制了答案

【讨论】:

  • 感谢 Wiz,我也尝试过 adjustPan(实际上尝试过 | 两者都在操作栏下方。奇怪....
猜你喜欢
  • 1970-01-01
  • 2016-02-01
  • 2011-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多