问题在于Android键盘在打开时会覆盖EditText下的TextView(而不是EditText本身!)。
以下是我的布局示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/big_image"
android:layout_width="200dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:src="@drawable/ic_launcher_foreground"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/comment_input_layout"
android:text="0/250"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
以下图片以便更清楚地说明:
我在stackoverflow上找到了几个相似的问题,但都没有解决方案:(请帮助我解决这个问题!
请确保我已经采用了所有关于android:windowSoftInputMode="adjustPan"
或android:windowSoftInputMode="adjustResize"
或android:focusableInTouchMode="true"
或android:fitsSystemWindows="true"
或将此textview添加到与edittext布局分离的位置,使用framelayout作为根元素等的建议。
但是问题有点复杂。
另一个重要的事情是,这个编辑文本框下面的文本应该
在文本换行时仍然位于键盘上方
在编辑文本向上滚动时消失(因为它是编辑文本框的一部分)。