安卓:我怎样才能使一个垂直列表视图水平滚动的物品?能使、视图、水平、物品

2023-09-06 15:36:29 作者:栀年

我想用horizo​​ntall在垂直滚动列表视图滚动的项目。

I would like to use horizontall scrolling items in a vertically scrolling Listview.

我的天真拿到这个是把里面滚动视图列表视图项的内容。该项目是较宽水平方向上比滚动视图,但不高于滚动视图。由于列表视图是一个正常的垂直滚动列表视图,我计算过,拖动垂直滚动会在列表中,拖动水平将滚动中的项目。

My naive take on this was to put the contents of the listview items inside a scrollView. The items are wider horizontally than the scrollview, but not higher than the scrollview. Since the listview is a normal vertically scrolling listview, I figured that dragging vertically would scroll in the list, while dragging horizontally would scroll in the items.

但没有奏效。该列表滚动精细垂直和正确显示的项目,但水平滚动无法正常工作(没有任何反应)。不幸的是,我真的不知道从哪里何去何从。

However that didn't work. The list scrolls fine vertically and shows the items correctly, but scrolling horizontally does not work (nothing happens). Unfortunately I am really not sure where to go from here.

请注意,该项目应水平滚动独立于其他项目,即整个列表拖动侧身的时候不应该横向滚动。

Note that the items should scroll horizontally independently of the other items, i.e the whole list should not scroll sideways when dragging sideways.

作为参考,我想在列表的行为类似于它在应用程序脉搏,如果你已经看到了。

As a reference, I would like the list to behave similar to what it does in the app 'Pulse', in case you have seen it.

推荐答案

请普通的的ListView 任何适配器您像而设计的项目布局是这样的:

Make ordinary ListView with any adapter you like but design the item Layout something like this:

<?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 与水平滚动项目。和这些项与其他项目independantly滚动。

You'll have Vertically Scrollable ListView with Horizontally Scrollable items. And the items are scrolled independantly from other items.