Android: How can I make horizontally scrollable items in a vertical list?

I would like to use horizontall scroll elements in a scrollable vertical Listview.

My naive lesson was to put the contents of list items in a scrollView. Elements are wider horizontally than scrollview, but no higher than scrollview. Since listview is a normal vertical scroll list, I decided that vertical drag and drop would scroll in the list, and horizontal drag would scroll in elements.

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

Please note that elements must scroll horizontally independently of other elements, i.e. the entire list should not scroll sideways while dragging sideways.

As a link, I would like the list to behave the same as in the Pulse application, if you saw it.

+5
source share
4 answers

Make it normal ListViewwith whatever adapteryou like, but create a Layout element 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>

You will be upright Scrollable ListViewwith horizontal Scrollableelements. And the elements scroll independently of the other elements.

+6
source
+3

Android, ScrollView ListView, bu Romain Guy android development, : ScrollView Android

:

" HorizontalScrollView ListView, ListView . , ListView , ListView , , HorizontalScrollView.

: , , , ​​ Android, , , . http://code.google.com/p/android/issues/detail?id=2781.

+2

You can use the "ViewPager", each item in the list can be a ViewPager

0
source

All Articles