如何在垂直滚动中添加水平垂直RecyclerView

时间:2016-02-02 12:39:34

标签: android android-recyclerview android-scrollview horizontalscrollview

我想在垂直滚动视图中添加垂直和水平RecyclerView。

是否可以在vertcal scrollview中包含多个回收站视图 我需要使用什么控件。

另外,在一个ScrollView中嵌套的RecyclerView也不是一个好习惯,所以任何人都可以告诉我,正确的做法是什么,我可以在另一个RecyclerView中添加RecyclerView,或者我只需要使用水平和垂直scrollview来实现这一点。

2 个答案:

答案 0 :(得分:0)

你可以做这样的事情,让两个RecyclerView嵌套在一个ScrollView中,这是不推荐的方式。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/tools"
    android:focusableInTouchMode="true"
    android:padding="8dp"
    android:background="@drawable/old_map"
android:layout_height="match_parent">

<ScrollView
    android:layout_below="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:scrollbars="none">

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

            <view
            android:scrollbarSize="6dp"
            android:id="@+id/recent_post"
            class="android.support.v7.widget.RecyclerView"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:scrollbars="vertical" />

            <view
            android:scrollbarSize="6dp"
            android:id="@+id/recent_post"
            class="android.support.v7.widget.RecyclerView"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:scrollbars="horizontal" />

</RelativeLayout>
    </ScrollView>
</RelativeLayout>

答案 1 :(得分:0)

我不知道你想要什么样的滚动但是可以同时使用两个滚动:

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

        <HorizontalScrollView
            android:id="@+id/HorizontalScrollView02"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

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

                <!-- HERE YOUR CODE-->
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</ScrollView>