Android - Recycleview Inside Scrollview

2019-09-16 04:38发布

I am building a social app and have an activity for viewing user's profiles (like Instagram).

I basically want to be able to scroll normally and naturally from the ScrollView to the RecyclerView and viceversa. So for example, if the user does a strong swipe from the bottom of the RecyclerView I want it to take him up to the top of the ScrollView . I was thinking of the following solution (but don't really know how to do it): make the RecyclerView's height "expanded" so it would contain all the items but with no scrollbar, so that the ScrollView can do it's a natural thing.

My layout looks like this:

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

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

   <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

  <!-- FIRST REGION THIS IS SET PRGRAMATICALLY TO TAKE UP WHOLE SCREEN-->

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

              <ImageView> <Textview> <Bla> <Bla>

         </RelativeLayout>

   <!-- SECOND REGION ALSO SET TO TAKE UP ALL SCREEN PROGRAMATICALLY-->

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

        <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"
             />

        </RelativeLayout>

   </LinearLayout>

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

</RelativeLayout>

Screenshots: First Region Second Region

1条回答
手持菜刀,她持情操
2楼-- · 2019-09-16 05:31

use this mRecyclerView.setNestedScrollingEnabled(false);

查看更多
登录 后发表回答