当它在android中的NestedScrollView中设置时,RecycleView不可见

时间:2017-08-15 05:50:50

标签: android android-recyclerview scrollview android-nestedscrollview nestedscrollview

如何在NestedScrollView中使用RecyclerView?设置适配器后,RecyclerView内容不可见。

无论如何,我已经尝试在NestedScrollView中使用RecyclerView,通过添加一个像framelayout或relativelayout这样的视图组作为nestedscrollview的单个子项,然后我在framelayout或relativelayout中添加了一个recyclerview)

提前致谢...

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorWhite">

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

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/nestedView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/appbar"
                android:fillViewport="true"                                   
               app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/profile_bg_clound"
                    android:orientation="vertical">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="5dp"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="15dp"
                        android:layout_marginTop="5dp">

                        <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
                            android:id="@+id/swipe_refresh_layout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">


                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/rv_driverRequests"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

                        </android.support.v4.widget.SwipeRefreshLayout>


                    </RelativeLayout>
                </LinearLayout>
            </android.support.v4.widget.NestedScrollView>



        </RelativeLayout>


    </android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:-2)

用这个替换你的RecycleView ......

<com.app.view.CustomRecyclerView
        android:id="@+id/rv_driverRequests"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

希望这会奏效。