Android - Recycleview Inside Scrollview

白昼怎懂夜的黑 提交于 2019-12-11 17:49:47

问题


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:


use this mRecyclerView.setNestedScrollingEnabled(false);



来源:https://stackoverflow.com/questions/45897819/android-recycleview-inside-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!