微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/android/310543.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐