aaa_bbb_ccc_sss 2017-09-20 15:12 采纳率: 100%
浏览 6675
已采纳

NestedScrollView嵌套RecyclerView,滚动事件被拦截

现有两个RecyclerView,每个都嵌套有NestedScrollView,部分代码如下

<android.support.v4.widget.NestedScrollView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@color/global_activity_background_color">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/goods_left_recycler_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </android.support.v7.widget.RecyclerView>
            </android.support.v4.widget.NestedScrollView>

            <android.support.v4.widget.NestedScrollView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:background="@color/global_background_color_white">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/goods_right_recycler_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </android.support.v7.widget.RecyclerView>
            </android.support.v4.widget.NestedScrollView> 

运行截图如下:
图片说明
我想点击左侧的item,右侧能滚动到相应位置,但是目前无任何响应,请问各位该如何解决。

  • 写回答

1条回答 默认 最新

  • yukuoyuan 2017-09-21 02:43
    关注

    1.首先我看到你的视图效果是完全不用嵌套使用,直接两个左右的Recycleview就可以了.如果非要外边包含一个Scroview的话,
    __(1).解决嵌套滑动默认抢占焦点问题,在最外层父布局设置两个属性,
    --(2)解决嵌套展示一条的问题以及滑动不流畅的问题,在Recycleview外边包一层Relativelayout,并设置属性 android:descendanFocusability="blocksDescendants"就可以解决

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?