android – 如何在垂直列表视图中制作水平滚动项?

前端之家收集整理的这篇文章主要介绍了android – 如何在垂直列表视图中制作水平滚动项?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在垂直滚动的Listview中使用horizo​​ntall滚动项.

我天真的想法是将listview项的内容放在scrollView中.项目在水平方向上比滚动视图宽,但不高于滚动视图.由于listview是一个普通的垂直滚动列表视图,我认为垂直拖动会在列表中滚动,而水平拖动会在项目中滚动.

但是那没用.列表垂直滚动并正确显示项目,但水平滚动不起作用(没有任何反应).不幸的是,我真的不确定从哪里开始.

请注意,项目应独立于其他项目水平滚动,即横向拖动时整个列表不应横向滚动.

作为参考,我希望该列表的行为类似于它在应用程序’Pulse’中的行为,以防您看到它.

解决方法

使用您喜欢的任何适配器制作普通的ListView,但设计项目布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <HorizontalScrollView
        android:id="@+id/hor_scroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/lin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/icon"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginRight="6.0dip"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:focusable="false" />

            <TextView
                android:textAppearance="?android:textAppearanceMedium"
                android:gravity="center_vertical"
                android:id="@+id/text"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:singleLine="true"
                android:layout_toRightOf="@id/icon"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true" />

        </LinearLayout>

    </HorizontalScrollView>


</RelativeLayout>

您将拥有具有水平可滚动项目的垂直可滚动ListView.并且这些项目与其他项目无关地滚动.

原文链接:https://www.f2er.com/android/310543.html

猜你在找的Android相关文章