Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何在一个屏幕上用RecyclerView显示两个片段_Android_Android Fragments_Scrollview_Android Recyclerview - Fatal编程技术网

Android:如何在一个屏幕上用RecyclerView显示两个片段

Android:如何在一个屏幕上用RecyclerView显示两个片段,android,android-fragments,scrollview,android-recyclerview,Android,Android Fragments,Scrollview,Android Recyclerview,我有两个片段,每个片段都有各自的RecyclerView列表。 来自每个片段的RecyclerView可能包含许多项。因此,滚动将是最有必要的。 我的问题是,如何使用ScrollView将这两个片段组合并显示在一个屏幕上,但同时使RecyclerViews的滚动行为正常(不粘性,跟随整个屏幕的滚动) 谢谢 编辑: 我的布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:/

我有两个片段,每个片段都有各自的RecyclerView列表。 来自每个片段的RecyclerView可能包含许多项。因此,滚动将是最有必要的。 我的问题是,如何使用ScrollView将这两个片段组合并显示在一个屏幕上,但同时使RecyclerViews的滚动行为正常(不粘性,跟随整个屏幕的滚动)

谢谢

编辑: 我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.easyuni.courserecommender.ResultsActivity">

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_below="@+id/toolbar">

                <FrameLayout
                    android:id="@+id/fragment_container_results_career"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />

                <View
                    android:id="@+id/divider"
                    android:layout_width="fill_parent"
                    android:layout_height="1dp"
                    android:layout_below="@+id/fragment_container_results_career"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:background="@color/divider" />

                <FrameLayout
                    android:id="@+id/fragment_container_results_courses"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />

            </LinearLayout>

        </RelativeLayout>

        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:itemIconTint="#333"
            app:itemTextColor="#333" />

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

</RelativeLayout>


你可以这样做-

在活动的布局文件中,应该有两个用于包含两个片段的framelayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/first_fragment_container"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

    </FrameLayout>

    <FrameLayout
        android:id="@+id/second_fragment_container"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

    </FrameLayout>
</LinearLayout>

在滚动视图中滚动是不好的做法,因为这种行为可能很奇怪。你真的需要那个滚动视图吗?无论如何,展示一些代码,看看你已经尝试了什么。@Amy是的,我知道这不是一个好的做法。我无法控制,因为我有数据需要显示在列表中,因此我必须使用RecyclerViews。我提到ScrollView是因为数据不能在单个屏幕视图中完全显示。或者,对于我应该如何解决这个问题,你有什么其他建议吗?谢谢为什么不能将一个RecyclerView与自定义行或Gridlayout一起使用?真的有必要有两个片段吗?@Amy很抱歉,因为两个RecyclerView显示不同的数据,并且每个都使用不同的布局管理器(第一个是线性的,第二个是网格)。好的,那么您的设置应该可以。但你想让它同时滚动?最好在每个片段中有2个接口,告诉另一个RecyclerView滚动到某个位置或按值滚动。这符合你的要求吗?很抱歉,这并不能完全解决我的问题。片段确实使用FrameLayouts显示,但每个片段中的RecyclerView会单独滚动。我想使整个屏幕作为一个页面滚动:(
 getSupportFragmentManager().beginTransaction().add(R.id.first_fragment_container, new YourFirstFragment()).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.second_fragment_container, new YourSecondFragment()).commit();