1

Как разместить два и более RecyclerView на одном активити. Причем они могут не влазить во весь экран, но с помощью ScrollView можно будет матать вниз. Пробовал реализовать через таблицу. Ну что-то всё не выходит

<LinearLayout 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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ewrei.testlayout.MainActivity">


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

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

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="527dp">

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

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

                    <TextView
                        android:text="Личный рейтинг"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/liznyi_rating"
                        android:textColor="@android:color/darker_gray"
                        android:layout_below="@+id/textView2"
                        android:layout_centerHorizontal="true" />

                    <TextView
                        android:text="000000000"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView2"
                        android:textColor="@android:color/darker_gray"
                        android:layout_below="@+id/imageView"
                        android:layout_centerHorizontal="true" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:srcCompat="@drawable/shot_012"
                        android:id="@+id/imageView"
                        android:layout_alignParentTop="true"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="24dp" />

                </RelativeLayout>

            </TableRow>

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

                <android.support.v7.widget.RecyclerView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/resurs"
                    android:layout_below="@+id/liznyi_rating"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true">

                </android.support.v7.widget.RecyclerView>
            </TableRow>

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

                <android.support.v7.widget.RecyclerView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/resurs2"
                    android:layout_below="@+id/liznyi_rating"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginTop="191dp" />
            </TableRow>
        </TableLayout>

    </LinearLayout>
</ScrollView>

Хочу, чтоб вот так было

Andrew
  • 17,943

2 Answers2

2

Нужно их поместить внутрь LinearLayout, ориентированный вертикально.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/in_app_friends"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:background="@color/white"/>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/friends_to_invite"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"/>
</LinearLayout>
</ScrollView>

Примечание: на самом деле, это костыльное решение. Вы можете просто внутри одного RecyclerView делать элементы разного типа, с разным же набором данных.

Andrew G
  • 2,054
2

Благодаря Andrew Grow начал искать библиотеки как сделать одним RececlerView и на толкнулся на библиотеку RendererRecyclerViewAdapter, которая очень проста и выполняет то что хотел. Да и пример рабочий есть. Так же пример вторая довольна интересен и прост для понимания

Glorfindel
  • 1,187
  • 2
  • 14
  • 19