Android 在布局中使用多个RecyclerViews进行Scolling
我创建了一个包含两个RecyclerViews的布局。一个水平滚动,另一个垂直滚动。我可以在每个RecyclerView中正确滚动,但页面作为一个整体不会滚动,即顶部RecyclerView始终保持在顶部,底部RecyclerView保持在底部,就像两者都固定在位置一样 以下是我的xml布局:Android 在布局中使用多个RecyclerViews进行Scolling,android,scrollview,android-linearlayout,android-recyclerview,Android,Scrollview,Android Linearlayout,Android Recyclerview,我创建了一个包含两个RecyclerViews的布局。一个水平滚动,另一个垂直滚动。我可以在每个RecyclerView中正确滚动,但页面作为一个整体不会滚动,即顶部RecyclerView始终保持在顶部,底部RecyclerView保持在底部,就像两者都固定在位置一样 以下是我的xml布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.androi
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:hint="Search Dramas"
android:textSize="16sp"
android:paddingLeft="10dp"
android:gravity="center"
android:textColor="@color/dark_grey"
android:textColorHint="@color/dark_grey"
android:background="@drawable/border_bottom"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom_background_black"
android:textColor="@color/white"
android:padding="10dp"
android:text="Most Watched"/>
<!-- A RecyclerView to display horizontal list -->
<android.support.v7.widget.RecyclerView
android:id="@+id/featured"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="240dp"
android:paddingLeft="0dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:paddingBottom="25dp"
android:background="@color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom_backgroundless"
android:textColor="@color/dark_grey"
android:padding="10dp"
android:text="All Dramas"/>
<!-- A RecyclerView to display vertical list -->
<android.support.v7.widget.RecyclerView
android:id="@+id/pick_item"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</LinearLayout>
RecyclerView在22.2.0版中只获得了嵌套滚动的支持(仍然有限)——我的第一个建议是尝试一下
唯一一个完全支持嵌套滚动的视图是(注意到它同时实现了和),它是在Support v4版本22.1.0中添加的(在22.2.0中略有改进)。如果您只有一个水平
回收视图
作为垂直回收视图
中的最顶端项目,你可以用一个NestedScrollView
代替它,它包含一个LinearLayout
,水平RecyclerView
,然后是垂直RecyclerView我可以通过将所有内容放在ScrollView中,然后设置垂直的高度来解决这个问题以手动/编程方式回收视图
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:hint="Search Dramas"
android:textSize="16sp"
android:paddingLeft="10dp"
android:gravity="center"
android:textColor="@color/dark_grey"
android:textColorHint="@color/dark_grey"
android:background="@drawable/border_bottom"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom_background_black"
android:textColor="@color/white"
android:padding="10dp"
android:text="Most Watched"/>
<!-- A RecyclerView to display horizontal list -->
<android.support.v7.widget.RecyclerView
android:id="@+id/featured"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="240dp"
android:paddingLeft="0dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:paddingBottom="25dp"
android:background="@color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom_backgroundless"
android:textColor="@color/dark_grey"
android:padding="10dp"
android:text="All Dramas"/>
<!-- A RecyclerView to display list -->
<android.support.v7.widget.RecyclerView
android:id="@+id/pick_item"
android:paddingBottom="20dp"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:minHeight="840dp"/>
</LinearLayout>
</ScrollView>
我在一个布局和一个滚动视图中使用了三个recycler视图。我的回收者视图第二个回收者视图中的项目被滚动。我想在不滚动的情况下显示所有项目。但是通过NestedScrollView获得了成功。谢谢你是不是失去了RecycleView优化功能?换句话说,RecycleView不会回收视图。
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// calculate height of RecyclerView based on child count
params.height=1150;
// set height of RecyclerView
recyclerView.setLayoutParams(params);