Android recyclerview无法在低端设备上滚动-为什么?

问题描述 投票:0回答:2

我有这个问题,我的recyclerview无法在api 19(lollipop)上进行nestedscrolling ...在最新版本的android上还可以。使用以下依赖项:com.android.support:design:26.1.0

并且我创建的是一个应该带有粘性标头的recyclerview。标头位于卡片视图中,列表项位于卡片视图下方。它看起来像这样:

detailscreen.xml:

 <!--wrapping in RelativeLayout until this is resolved: https://stackoverflow.com/questions/57142959/why-latest-version-constraintlayout-doesnt-work-in-nestedscrollview-with-coordi-->

<RelativeLayout 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="match_parent"
    android:orientation="vertical">

<androidx.cardview.widget.CardView
    android:id="@+id/headerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="@string/ride_hail_meet_at"
            android:textColor="#388bf2"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />



        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_weatherdata"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:nestedScrollingEnabled="false"
            android:orientation="horizontal"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_constraintLeft_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tv_description"
            tools:itemCount="3"
            tools:listitem="@layout/weather_data_row_item"
            tools:visibility="visible" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

<RelativeLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/headerView"
    android:layout_alignParentBottom="true"
    android:background="@color/white">


<!--  THIS IS THE RECYCLERVIEW GIVING ME THE PROBLEMS. ITS NOT SCROLLING ON API 19 , WHY ??? -->


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_directions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="16dp"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:itemCount="5"
        tools:listitem="@layout/ride_direction_row" />


</RelativeLayout>

当我给它充气时,将其放置在CoordinatorLayout customView中。该容器本身可以滚动。我在最新版本的android上工作而不是lollipop上的工作错了吗?我什至尝试使用appBarLayout并将我的headerView放在那,但同样的事情只是在旧版本的android上不起作用。如果您可以提出更好的方法,我是否愿意完全更改xml?

注:设置android:nestedScrollingEnabled = false将导致我的recyclerView不重新生成recyclerviews。我在列表中有大图像,所以我需要此功能。

android android-layout android-recyclerview android-nestedscrollview
2个回答
0
投票

您必须将android:layout_height设置为match_parent或固定大小。

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

如果将其设置为wrap_content,它将扩展到其内容的大小,因此不会滚动。


0
投票

很奇怪,这是我可以解决它的唯一方法:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/recyclerview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"

      app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.google.android.material.appbar.AppBarLayout
      android:id="@+id/appbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"    
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

      <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleGravity="bottom"
        app:expandedTitleMarginEnd="@dimen/activity_horizontal_margin"
        app:expandedTitleMarginStart="@dimen/activity_horizontal_margin"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed"

        app:title="@string/app_name">

        <ImageView
          android:id="@+id/toolbar_image"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:adjustViewBounds="true"
          android:contentDescription="@null"
          android:fitsSystemWindows="true"
          android:scaleType="centerCrop"
          android:src="@drawable/beach_huts" />


      </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

太奇怪了,它适用于所有事物..谢谢大家。

© www.soinside.com 2019 - 2024. All rights reserved.