如何在 1 个线性布局中将多个回收器视图与垂直滚动结合起来

how to combine multiple recycler views with a scroll vertically in 1 linear layout

我正在尝试在 1 个线性布局中使用 2 个回收器视图。 回收站视图将生成自己的滚动条,但其他数据在屏幕上保持不变,那么如何将所有内容合并到 1 个滚动区域?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grey"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:weightSum="100">

            <LinearLayout
                android:id="@+id/sliderhome"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="70">


                <com.daimajia.slider.library.SliderLayout
                    android:id="@+id/slider"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|enterAlways"
                    />
                <com.daimajia.slider.library.Indicators.PagerIndicator
                    android:id="@+id/custom_indicator"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    />

            </LinearLayout>

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

                <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:context="vlabs.chorbazaar.HomeFragment"
                    android:background="@color/white"
                    android:orientation="horizontal">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"/>

                </FrameLayout>
            </LinearLayout>
    </LinearLayout>

我试图让我的滑块和回收器视图作为一个整体滚动,但滑块卡在一个固定的位置,而回收器视图像往常一样滚动。

更改xml文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:weightSum="100">

<LinearLayout
    android:id="@+id/sliderhome"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="70">


    <com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        />
    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        />

</LinearLayout>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

viewpager 适配器:

private class MyPagerAdapter extends FragmentPagerAdapter {
    ArrayList<String> arrayList
    public MyPagerAdapter(FragmentManager fm, ArrayList<String> arrayList ) {
        super(fm);
        this.arrayList = arrayList;
    }

    @Override
    public Fragment getItem(int pos) {
        switch(pos) {

        case 0: return FirstFragment.newInstance(arraylist);
        case 1: return SecondFragment.newInstance(arraylist);
    }

    @Override
    public int getCount() {
        return 2;
    }       
}

}

活动中:

ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), arrayList));

xml 文件中的片段:

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


        <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>