通过水平和垂直滚动创建一个RecyclerView [英] Create a RecyclerView with both horizontal and vertical scrolling

查看:147
本文介绍了通过水平和垂直滚动创建一个RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几周里,我一直在学习使用RecyclerView.我需要实现一个水平列表,即通过将设备以横向模式旋转,就像这样:

我找到了最佳解决方案(如何创建RecyclerView的水平位移,解决方案

我对应用程序中出现的所有问题都感到非常生气,而这些问题并未考虑到最简单的解决方案.

RecyclerView中,它由两个XML文件组成,其中一个主要是声明RecyclerView的XML文件,另一个是带有内容的文件.

最简单的解决方案是在ScrollView中引入RecyclerView.因此,通过ScrollView可以水平和垂直移动所有项目,而在横向模式下,通过RecyclerView可以移动项目.

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>

Over the past few weeks I've been learning to use the RecyclerView. I need to implement a horizontal list, ie, that by turning the device in landscape mode like so:

I found the best solution for this (how to create the horizontal displacement of RecyclerView, here), but encountered another problem. The item RecyclerView was larger than the height of the device (in landscape, horizontal), so I need to create a vertical and horizontal displacement, simultaneously.

I looked at the Android Developer methods for the LayoutManager class, but my skills are not high enough to understand most of the methods. I also tried putting a RecyclerView vertically inside another RecyclerView horizontally with all the content, but I get error:

IllegalStateException: RecyclerView has no LayoutManager

To rememedy this I removed all <View ... /> elements from the XML file, but this does not give any results.

To clarify what I am asking: is it possible to have my layout scroll both horizontally and vertically, and if you could explain how I would appreciate it.

解决方案

I was so angry about all the problems that had tended with the application that had not thought about the easiest solution.

In a RecyclerView consists of two XML files, the main one where the RecyclerView is declared and another with content.

The simplest solution was to introduce the RecyclerView within a ScrollView. So I can move all items at a time thanks to ScrollView vertically and horizontally I can move the items thanks to RecyclerView in landscape mode.

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>

这篇关于通过水平和垂直滚动创建一个RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆