【问题标题】:RecycleView not scrollingRecyclerView不滚动
【发布时间】:2019-07-26 05:54:46
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/bottomSheetLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_top_round_corner">

    <androidx.cardview.widget.CardView
    android:id="@+id/cardViewInnerProductContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:cardElevation="10dp"
    app:cardCornerRadius="10dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/closeIv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="12dp"
            android:src="@drawable/ic_close_dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/changeAddressTitleTv"
            style="@style/FontLocalizedBold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="7dp"
            android:paddingStart="12dp"
            android:text="@string/changeaddress_popup_change_address"
            android:textColor="@color/colorTextPrimary"
            android:textSize="20sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/closeIv" />

        <View
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorDividerLight"
            app:layout_constraintTop_toBottomOf="@id/closeIv" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/locationRv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/divider"
            tools:listitem="@layout/item_choose_address" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/addressesRv"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingBottom="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/locationRv"
            tools:listitem="@layout/item_choose_address" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>



        val addressesLayoutManager = LinearLayoutManager(context)
        addressesLayoutManager.orientation = RecyclerView.VERTICAL
        addressesRv.layoutManager = addressesLayoutManager

addressesRvrecycleView 没有滚动。我在底页对话框中有这个设置。它只是采用 200dp 的高度大小并仅显示适合的项目,我无法滚动浏览所有项目。

我试图取出CardView,删除视图中的另一个回收,将addressesRv 包装在NestedScrollLayout 中,但滚动都不起作用。

编辑:

【问题讨论】:

  • 你为 RecyclerView 做过 recyclerview.setNestedScrolling(false) 了吗?
  • @Piyush 是的,没有效果。

标签: android kotlin android-recyclerview scroll android-constraintlayout


【解决方案1】:

如果你放了 NestedScrollview,就把它去掉。

并将其添加到您的地址Rv recyclerview

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"

【讨论】:

  • 如果你放了NestedScrollview,就把它去掉。
  • 请编辑您的回复并添加此评论,谢谢!
【解决方案2】:

因为您在同一页面中使用多个Recyclerview,我认为recyclerView 都有垂直方向的LinearLayout 管理器。我发现你的第一个回收站视图高度是wrapContent,但第二个是固定的。所以这里有一个变化滚动问题。所以这里你需要nestedScrolview

nestedScrollView 会做什么?:

Ans:它将帮助您滚动两个recyclerview。

关于问题的更多讨论: 假设您的第一个 recyclerView 有 10 个元素,这些元素覆盖全屏,但您的第二个 recyclerView 也有 10 个元素。现在两个 recyclerView 都没有一起显示所有元素。因为没有nestedScrollView就无法滚动

代码示例:

<androidx.cardview.widget.CardView
    android:id="@+id/cardViewInnerProductContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:cardElevation="10dp"
    app:cardCornerRadius="10dp">

 <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
       // Your other code
  </androidx.constraintlayout.widget.ConstraintLayout>
  </androidx.core.widget.NestedScrollView>

【讨论】:

  • 我想要修复第一个循环,它总是有两个元素。首先所有区域都是可滚动的,然后请求修复前两个。正如我所说,我试图删除一个回收站,但结果相同,而不是滚动。我已将 addressesRv 包裹在 NestedScrollView 中,但没有效果
  • 你必须在 CardView 之后使用nestedScrollView。
  • 你能发布一个 xml 示例吗?
  • 卡片视图在nestedScrollView内包裹约束布局后
  • 它只在一个方向上起作用。如果我想向下滚动,它会关闭底部工作表,即使列表尚未到达顶部。
【解决方案3】:

试试这个将你的约束布局放在 CoOrdinator 布局中

<android.support.design.widget.CoordinatorLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

    【解决方案4】:

    如何在 RecyclerView 中添加类?您必须在类中设置 LayoutManager。示例:

    recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.HORIZONTAL));
    

    【讨论】:

      猜你喜欢
      • 2020-07-09
      • 2018-08-04
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多