Android RecyclerView项在键盘弹出时变形
我正在使用一个对话框(扩展DialogFragment)的一个活动,该对话框包含一个回收器视图(w:match parent,h:200dp),在回收器视图下方有一个编辑文本和按钮,只要编辑文本处于焦点且键盘弹出,回收器视图中的项目就会变形。对话框根视图(卡片视图)具有w:match_父项h:wrap_内容,列表项根视图(约束布局)具有w:match_父项h:wrap_内容 对话框:Android RecyclerView项在键盘弹出时变形,android,android-studio,android-layout,android-recyclerview,Android,Android Studio,Android Layout,Android Recyclerview,我正在使用一个对话框(扩展DialogFragment)的一个活动,该对话框包含一个回收器视图(w:match parent,h:200dp),在回收器视图下方有一个编辑文本和按钮,只要编辑文本处于焦点且键盘弹出,回收器视图中的项目就会变形。对话框根视图(卡片视图)具有w:match_父项h:wrap_内容,列表项根视图(约束布局)具有w:match_父项h:wrap_内容 对话框: <?xml version="1.0" encoding="utf-8"?> <andro
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="350dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginStart="20dp"
android:fontFamily="@font/opensans_bold"
android:gravity="center_vertical"
android:text="@string/label_add_remark"
android:textColor="@color/colorPrimary"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/windowBackground" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_revisit_remarks"
android:layout_width="match_parent"
android:layout_height="@dimen/revisit_rv_size"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="6"
tools:listitem="@layout/layout_remark_item" />
<LinearLayout
android:id="@+id/ll_add_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/rectangle_grey_border"
android:minWidth="250dp"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rv_remarks">
<EditText
android:id="@+id/et_add_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:layout_weight="2"
android:background="@null"
android:hint="@string/add_your_comment"
android:inputType="textMultiLine|textCapSentences"
android:minHeight="40dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/primaryTextColor"
android:textColorHint="@color/text_color_light"
android:textSize="12sp" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/button_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:backgroundTint="@color/colorPrimary"
android:fontFamily="@font/opensans_bold"
android:text="@string/submit"
android:textAllCaps="false"
android:textColor="@color/white"
android:translationZ="0dp"
app:cornerRadius="4dp"
app:elevation="0dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
清单项目:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="?attr/selectableItemBackground"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<ImageView
android:id="@+id/iv_profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/image_member_sample" />
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:fontFamily="@font/opensans_semibold"
android:lines="1"
android:textColor="@color/text_color_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_profile_image"
app:layout_constraintTop_toTopOf="@id/iv_profile_image"
tools:text="BIna Antony Mari Kurian Paulose" />
<TextView
android:id="@+id/tv_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="20dp"
android:fontFamily="@font/opensans_regular"
android:textColor="@color/text_color_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/tv_name"
app:layout_constraintTop_toBottomOf="@id/tv_name"
tools:text="@tools:sample/lorem" />
</androidx.constraintlayout.widget.ConstraintLayout>
试试这个:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u RESIZE)