【问题标题】:No scrolling for RecyclerView android Lollipop 5.xRecyclerView android Lollipop 5.x 没有滚动
【发布时间】:2017-10-16 06:44:27
【问题描述】:

为 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,item 布局为:

<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)中也观察到没有滚动,但观察结果不同。在 Spinners 的情况下,会显示下拉列表,但所选项目不会反映在 UI 上。 所有视图都在 Fragment 中膨胀。

【问题讨论】:

    标签: android android-5.0-lollipop android-recyclerview


    【解决方案1】:
    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>
    

    【讨论】:

    • 感谢您的回复,但它对我不起作用,基本上我没有明白你的意思,如果我为itemlayout 添加ScrollView 有什么不同,你能说得更清楚吗?我?
    • 为了更好地理解您的代码,您能否提供您的邮件 ID,以便我可以看到您的代码,以便为您提供更好的解决方案
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2015-04-05
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多