【问题标题】:RecyclerView item get deforme as keyboard pop upRecyclerView 项目在键盘弹出时变形
【发布时间】:2020-05-25 15:10:53
【问题描述】:

我是一个活动,我正在使用一个对话框(它扩展了 DialogFragment),对话框包含一个回收器视图(w:匹配父级,h:200dp),并且在回收器下方查看一个编辑文本和按钮,只要编辑文本成为焦点并且键盘在回收站视图中弹出项目变形。对话框根视图(卡片视图)具有 w:match_parent h:wrap_content 和列表项根视图(约束布局)具有 w:match_parent h:wrap_content

enter image description here

对话框:

 <?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>

【问题讨论】:

    标签: android android-studio android-layout android-recyclerview


    【解决方案1】:

    试试这个:

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      相关资源
      最近更新 更多