提问者:小点点

创建具有水平和垂直滚动的RecyclerView


在过去的几周里,我一直在学习使用RecyclerView。我需要实现一个水平列表,即通过将设备转换为横向模式,如下所示:

我找到了对此的最佳解决方案(如何在此处创建RecyclView的水平位移),但遇到了另一个问题。项目RecyclView大于设备的高度(横向、水平),因此我需要同时创建垂直和水平位移。

我查看了LayoutManager类的Android Developer方法,但我的技能不够高,无法理解大多数方法。我还尝试将Recy―View垂直放在另一个Recy―View水平放置所有内容,但我得到了错误:

IllegalStateException:RecyclerView没有LayoutManager

为了解决这个问题,我删除了所有

澄清我在问什么:是否可以让我的布局水平和垂直滚动,如果您能解释一下我会如何欣赏它。


共2个答案

匿名用户

我对应用程序中出现的所有问题感到非常愤怒,因为这些问题没有想到最简单的解决方案。

RecyclerView 中,由两个 XML 文件组成,一个主文件在其中声明 RecyclerView,另一个包含内容。

最简单的解决方案是在ScrollView中引入RecyclerView。因此,由于ScrollView,我可以一次垂直和水平移动所有项目,我可以在横向模式下移动这些项目。

< code>activity_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/cardIn_margin_ext">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbarStyle="outsideInset"
            android:scrollbars="horizontal" />

</ScrollView>

匿名用户

接受的答案对我不起作用。我不得不使用水平滚动视图,而不是简单的滚动视图。

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_margin="@dimen/cardIn_margin_ext">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbarStyle="outsideInset"
        android:scrollbars="horizontal" />
</HorizontalScrollView >