首页 > 解决方案 > 为什么 RecyclerView 项目在键盘出现时损坏?

问题描述

我有以下布局结构:

NestedScrollView
   ConstrainstsLayout
      SearchView
      RecyclerView
      RecyclerView

当我点击 时SearchView,键盘出现并且底部的项目RecyclerView变大。不能一起查看项目RecyclerView。他们只一一展示,因为他们的高度,在展示键盘后变得更大。那么,如何解决问题呢?这是布局。

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

    <variable
        name="viewModel"
        type="tech.nplus.yaptk.ui.payment.PaymentViewModel" />

</data>


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.SearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:iconifiedByDefault="false"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:queryHint="@string/find_service"

            />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/fast_payment_rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/searchView" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/service_list_parent_rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            app:items="@{viewModel.items}"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/fast_payment_rv"

            />

    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

这是3个屏幕。1 显示键盘出现之前,2 显示之后(注意元素消失),3 显示元素如何变大。 在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

PS我把android:windowSoftInputMode="adjustPan",否则,我的BottomNavigationView出现在键盘上方。

标签: android

解决方案


推荐阅读