如何在垂直列表视图中制作可水平滚动的项目? [英] How can I make horizontally scrollable items in a vertical listview?
问题描述
我想在垂直滚动的Listview中使用水平滚动项.
I would like to use horizontall scrolling items in a vertically scrolling Listview.
我对此的幼稚做法是将listview项的内容放入scrollView中.这些项目的水平宽度大于滚动视图,但不大于滚动视图.由于listview是正常的垂直滚动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.
作为参考,我希望该列表的行为类似于在应用程序"Pulse"中执行的操作,以防万一.
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
与您喜欢的任何adapter
相同,但设计项目布局应如下所示:
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>
您将拥有垂直Scrollable ListView
和水平Scrollable
项.并且项目独立于其他项目滚动.
You'll have Vertically Scrollable ListView
with Horizontally Scrollable
items. And the items are scrolled independantly from other items.
这篇关于如何在垂直列表视图中制作可水平滚动的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!