Android Studio 创建具有水平和垂直滚动功能的滚动视图

pbpqsu0x  于 11个月前  发布在  Android
关注(0)|答案(3)|浏览(158)

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


的数据
我找到了最好的解决方案(如何创建RecyclerViewhere的水平位移),但遇到了另一个问题。项目RecyclerView大于设备的高度(横向,水平),所以我需要同时创建垂直和水平位移。
我查看了LayoutManager类的Android Developer方法,但我的技能不足以理解大多数方法。我还尝试将一个RecyclerView垂直放置在另一个RecyclerView水平放置的所有内容中,但我得到错误:
IllegalStateException:异常:
为了记住这一点,我从XML文件中删除了所有<View ... />元素,但这并没有给予任何结果。
为了澄清我的问题:是否有可能让我的布局水平和垂直滚动,如果你能解释我将如何欣赏它。

ut6juiuv

ut6juiuv1#

我对所有的问题都很生气,这些问题倾向于没有想到最简单的解决方案的应用程序。
RecyclerView中,它由两个XML文件组成,其中一个主要文件声明了ClerView,另一个文件包含内容。
最简单的解决方案是在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>

字符串

u3r8eeie

u3r8eeie2#

接受的答案对我不起作用。我不得不使用HorizontalScrollView而不是简单的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 >

字符串

1hdlvixo

1hdlvixo3#

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

字符串

相关问题