【问题标题】:How can I add horizontal, vertical RecyclerView inside a vertical scroll如何在垂直滚动中添加水平、垂直 RecyclerView
【发布时间】:2016-02-02 12:39:34
【问题描述】:

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

垂直滚动视图中是否可以有多个回收器视图 我需要使用什么控件。

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

【问题讨论】:

  • 你的问题不是很清楚,你能解释一下你到底想在这里实现什么吗?
  • 在另一个滚动视图中拥有可滚动视图并不是一个好主意。如果需要,您应该为回收站视图设置默认高度。
  • 我想实现google play首页之类的东西
  • 使用NestedScrollView代替ScrollView,你可以添加Horizontal RecyclerView

标签: android android-recyclerview android-scrollview horizontalscrollview


【解决方案1】:

你可以这样做让两个 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>

【讨论】:

    【解决方案2】:

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

        <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>
    

    【讨论】:

    • 我想在滚动视图中有水平列表
    • 是否可以使用回收站视图
    猜你喜欢
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 2019-04-16
    • 1970-01-01
    相关资源
    最近更新 更多