嵌套的RecyclerView不滚动 [英] Nested RecyclerView not scrolling

查看:92
本文介绍了嵌套的RecyclerView不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将另一个回收器视图添加到另一个回收器视图时遇到问题.子回收者位于CardView内,而CardView则位于父回收者视图内.我在互联网上尝试了所有解决方案,没有任何用处.我希望子回收者视图垂直滚动,而父回收者视图也垂直滚动.

I'm having a problem adding a recycler view inside another recycler view. The child recycler is inside a CardView and the CardView is inside the parent recycler view. I tried all solutions on the internet and no use. I want the child recycler view to scroll vertically while the parent recycler view also scroll vertically.

家长回收者"视图:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundPrimary"
    tools:context=".BidsCenter">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/bidCenter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        />
</FrameLayout>

儿童回收者视图:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
    android:layout_margin="5dp"
    android:animateLayoutChanges="true"
    android:clickable="true"
    android:elevation="3dp"
    android:focusable="true"
    android:orientation="vertical"
    app:cardCornerRadius="10dp">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp">

        <RelativeLayout
            android:id="@+id/r0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/itemPreviewInCenter"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:layout_margin="3dp"
                android:scaleType="fitCenter"
                android:src="@android:drawable/ic_menu_report_image" />

            <TextView
                android:id="@+id/itemTitleInCenter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_margin="3dp"
                android:layout_toStartOf="@+id/itemPreviewInCenter" />

            <TextView
                android:id="@+id/totalBidPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerVertical="true"
                android:layout_toEndOf="@+id/numberOfBids"
                android:background="@drawable/bid_total"
                android:clickable="false" />

            <TextView
                android:id="@+id/latestBidDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_margin="3dp"
                android:layout_toEndOf="@id/bidMenu" />

            <TextView
                android:id="@+id/numberOfBids"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_centerVertical="true"
                android:layout_margin="3dp"
                android:layout_toEndOf="@+id/latestBidDate"
                android:background="@drawable/new_message_count"
                android:gravity="center"
                android:textColor="@color/text"
                android:visibility="gone" />

            <ImageButton
                android:id="@+id/bidMenu"
                style="?android:attr/actionOverflowButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/showBidders"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/r0"
            android:orientation="vertical"
            android:visibility="gone">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:layout_margin="3dp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/latestBidsInCenter"
                android:layout_width="match_parent"
                android:layout_height="120dp" />
        </LinearLayout>
    </RelativeLayout>
</androidx.cardview.widget.CardView>

这是一些屏幕截图

父母:

孩子:

推荐答案

已编辑

滚动子级时必须禁用父级recyclerView触摸事件Recyclerview

you have to disable parent recyclerView touch event while scrolling child Recyclerview

latestBidsInCenter.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == child.getId()) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_UP) {
                bidCenter.requestDisallowInterceptTouchEvent(false);
            } else {
                bidCenter.requestDisallowInterceptTouchEvent(true);
            }
        }

        return super.onTouchEvent(event);
    }
});

这篇关于嵌套的RecyclerView不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆