【问题标题】:RecyclerView shrinks when keyboard opensRecyclerView 在键盘打开时缩小
【发布时间】:2021-10-16 12:44:06
【问题描述】:

我有这个回收站视图

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/serviceRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@+id/addNewServiceBtn"
    app:layout_constraintBottom_toBottomOf="parent"
    android:paddingBottom="10dp"
    android:layout_marginTop="20dp"
    />

里面有这个

 <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/serviceSelectExpertRegisterContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/border_edit_text"
    android:layout_marginHorizontal="20dp"
    android:paddingVertical="5dp"
    >
    <Spinner
        android:id="@+id/serviceSelectExpertRegister"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        app:layout_constraintTop_toTopOf="parent"
        android:spinnerMode="dropdown"
        />


</androidx.constraintlayout.widget.ConstraintLayout>


<EditText
    android:id="@+id/serviceDescriptionExpertRegister"
    app:layout_constraintTop_toBottomOf="@+id/serviceSelectExpertRegisterContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="20dp"
    android:hint="@string/service_description"
    android:background="@drawable/border_edit_text"
    android:padding="8dp"
    android:layout_marginTop="15dp"
    android:gravity="top|start"
    android:inputType="textMultiLine"
    android:lines="3"
    android:textColor="@color/light_grey"
    />

当我打开我的键盘时,它会缩小,如图所示 this is the shrinked image

this is not shrinked one

我已经尝试过 android:windowSoftInputMode="adjustPan"(以及所有其他 windowSoftInputModes),但它仍然有相同的反应。

有什么办法可以让布局上升并影响任何事情。

【问题讨论】:

  • 这个问题解决了吗?我也面临同样的问题。

标签: android xml android-layout android-recyclerview


【解决方案1】:

只需添加

android:windowSoftInputMode="adjustResize"

android:windowSoftInputMode="adjustPan|adjustResize"

或 您可以在 onCreate 中添加这一行

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【讨论】:

  • 正如我在问题上提到的那样,我已经尝试过这样做以及所有其他组合,但它仍然无法正常工作,我认为它与 RecyclerView 或片段 recyclerview 相关
【解决方案2】:

在适配器类的 onBindViewHolder 方法中使用以下代码

holder.setIsRecyclable(false);

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 2016-12-28
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多