我正在尝试创建一个包含几个
尝试的解决方案:
TextInputEditText
元素的活动。这些元素位于页面的中央位置,当键盘出现时会被覆盖。因此,我尝试在 AppManifest.xml
中使用 windowSoftInputMode="adjustPan"
,以便在键入时屏幕滚动以保持文本框可见。
然而,所有尝试都似乎失败了。以下是我使用的布局层次结构,以及我已经尝试过但未成功的解决方案示例。
layout xml
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:isScrollContainer="false">
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/inputA"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/inputAText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/inputB"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/inputBText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
AndroidManifest.xml片段
<activity
android:name=".activities.MyActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="sensorPortrait"
android:theme="@style/AppTheme.NoActionBar" />
尝试的解决方案:
- 在
AppManifest.xml
中的相关activity
中添加windowSoftInputMode="adjustPan"
(我还尝试了其他StackOverflow建议中的adjustResize
和adjustPan|adjustNothing
) - 将
ConstraintLayout
放置在ScrollView
中 - 在该ScrollView中添加
android:isScrollContainer="false"
- 使用仅包含
ConstraintLayout
和底部被约束的TextInputEditText
的布局文件重新创建布局文件 - 将
TextInputEditText
更改为EditText
并删除TextInputLayout
- 将
ConstraintLayout
更改为RelativeLayout
android:windowSoftInputMode="adjustPan"
,但不幸的是这也没有起作用。 - Tom Barden