Android - Recycleview Inside Scrollview



我正在构建一个社交应用程序,并有一个查看用户个人资料的活动(如Instagram(。

我基本上希望能够正常自然地从ScrollView滚动到RecyclerView,反之亦然。因此,例如,如果用户从RecyclerView的底部进行有力的滑动,我希望它将他带到ScrollView的顶部。我在想以下解决方案(但真的不知道该怎么做(:使RecyclerView的高度"展开",以便它包含所有项目但没有滚动条,以便ScrollView可以做到这一点是很自然的事情。

我的布局如下所示:

<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>

截图: 第一区域 第二区域

使用此mRecyclerView.setNestedScrollingEnabled(false);

最新更新