RecyclerView 没有滚动 android Lollipop 5.x

No scrolling for RecyclerView android Lollipop 5.x

为了 Android 5.X ( Lollipop ) 与 RecyclerVivew 斗争,我设计了简单的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@android:color/white"
  android:orientation="vertical">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:weightSum="4">
    <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.1"
      android:gravity="center"
      android:orientation="vertical">

      <TextView
        android:id="@+id/tvAuditStartDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/to" />

      <TextView
        android:id="@+id/tvAuditEndDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.2"
      android:gravity="center"
      android:orientation="vertical">

      <TextView
        android:id="@+id/tvAuditDepartmentName"
        style="@style/TextviewPrimaryMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center"
        android:lines="1" />

      <TextView
        android:id="@+id/tvSubItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center" />

    </LinearLayout>

    <FrameLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.2">

      <TextView
        android:id="@+id/tvAuditSubmitDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
    </FrameLayout>

    <FrameLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="0.5">

      <CheckBox
        android:id="@+id/chkbAuditStatus"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center"
        android:background="@drawable/check_box"
        android:button="@android:color/transparent"
        android:clickable="false"
        android:gravity="end" />
    </FrameLayout>
  </LinearLayout>
  <View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray" />
</LinearLayout>

自定义 RecyclerView.Adapter 附加到它,项目布局为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@android:color/white"
  android:orientation="vertical">
  <LinearLayout
      android:baselineAligned="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:orientation="horizontal"
    android:weightSum="4">
    <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.1"
      android:gravity="center"
      android:orientation="vertical">

      <TextView
        android:id="@+id/tvAuditStartDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/to" />

      <TextView
        android:id="@+id/tvAuditEndDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.2"
      android:gravity="center"
      android:orientation="vertical">

      <TextView
        android:id="@+id/tvAuditDepartmentName"
        style="@style/TextviewPrimaryMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center"
        android:lines="1"/>

      <TextView
        android:id="@+id/tvSubItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center" />

    </LinearLayout>

    <FrameLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1.2">

      <TextView
        android:id="@+id/tvAuditSubmitDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
    </FrameLayout>

    <FrameLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="0.5">

      <CheckBox
        android:id="@+id/chkbAuditStatus"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center"
        android:background="@drawable/check_box"
        android:button="@android:color/transparent"
        android:clickable="false"
        android:gravity="end" />
    </FrameLayout>
  </LinearLayout>
  <View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray" />
</LinearLayout>

现在此设置的问题是,此设置在除 5.X 以外的所有 android 版本中都运行良好,因为没有滚动到 RecyclerView。此外,这并不是观察者没有滚动的唯一情况,但在其他视图(如具有不同观察的 Spinner)中也观察到没有滚动。如果是微调器,则会显示下拉列表,但所选项目不会反映在 UI 上。 所有视图都在 Fragment 中膨胀。

Just try to implement this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent"

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="4">
<LinearLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1.1"
  android:gravity="center"
  android:orientation="vertical">

  <TextView
    android:id="@+id/tvAuditStartDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/to" />

  <TextView
    android:id="@+id/tvAuditEndDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1.2"
  android:gravity="center"
  android:orientation="vertical">

  <TextView
    android:id="@+id/tvAuditDepartmentName"
    style="@style/TextviewPrimaryMedium"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:gravity="center"
    android:lines="1" />

  <TextView
    android:id="@+id/tvSubItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:gravity="center" />

</LinearLayout>

<FrameLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1.2">

  <TextView
    android:id="@+id/tvAuditSubmitDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />
</FrameLayout>

<FrameLayout
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="0.5">

  <CheckBox
    android:id="@+id/chkbAuditStatus"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_gravity="center"
    android:background="@drawable/check_box"
    android:button="@android:color/transparent"
    android:clickable="false"
    android:gravity="end" />
</FrameLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />

 </LinearLayout>

  </ScrollView>
  </LinearLayout>

我已经通过将支持库更新到 com.android.support:design:25.2.0 解决了这个问题。也不知道这背后的原因以及它到底有什么不同。如果有人发现任何原因,请让所有人知道。这会很有帮助。谢谢。