SwipeRefreshLayout内的NestedScrollView内的RecyclerView不能平滑滚动

时间:2018-02-10 08:49:19

标签: android android-recyclerview android-nestedscrollview

这是我的布局。

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/activity_main_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_marginBottom="45dp"
        android:layout_height="wrap_content">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true">

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp"
                android:id="@+id/noob_button"
                android:text="haha" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/noob_button"
                android:orientation="vertical"
                android:clipToPadding="false"
                android:scrollbars="vertical" />
        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

这都在RelativeLayout内。

我已设置recyclerview.setNestedScrol..(false);

它仍然挂起,如果我设置RecyclerView的固定高度,它就不会挂起。它滚动但滚动不顺畅。

1 个答案:

答案 0 :(得分:0)

RecyclerView内部实际上并不需要NestedScrollView。据我所知,您需要在按钮下方ButtonRecyclerView。因此,您可以考虑将Button添加为RecyclerView的标题,这是更简洁的实现。

如果您考虑在RecyclerView中添加标题,请参阅my answer here了解如何实现这一目标。

我已经解释了如何添加页脚。同样的规则也适用于添加标题视图。如果您对此有任何疑问,请与我们联系。

相关问题