首页 > 解决方案 > 如何在 Android 中创建水平和垂直滚动的列表视图?

问题描述

我需要一个在垂直和水平方向滚动的列表视图。

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="always"
    android:scrollbarAlwaysDrawVerticalTrack="true">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:scrollbars="vertical|horizontal">

    </ListView>
</HorizontalScrollView>

这是我的代码,但它只制作水平列表视图。

这张图片是我的列表视图,只水平滚动。

标签: androidscrollandroid-listviewandroid-scrollview

解决方案


首先。不要使用列表视图。而是使用带有自定义 LayoutManager 的 RecyclerView。

作为解决方案,试试这个。 创建具有水平和垂直滚动的 RecyclerView


推荐阅读