Ngo Van
Ngo Van

Reputation: 887

Android: Horizontal ListView

I have a task like this:
Assume I have a list of 28 items.
I want to display 5 items at a time in the screen horizontally.
When user touch and drag to the left, it will be update by the next 5 items.
When user touch and drag to the right it will be update by the previous 5 items.
I don't know how to do it.
I need help, please!

Upvotes: 0

Views: 5555

Answers (2)

Ankit Popli
Ankit Popli

Reputation: 2837

Solution 1:

A combination of HorizontalScrollView and LinearLayout with horizontal orientation should work for you.

<HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:orientation="horizontal" >
            <!-- your items here -->
    </LinearLayout>
</HorizontalScrollView>

Solution 2:

If you are certain that you want the whole batch of items to get replaced, then you should go for ViewPager.

Hope this helps. :)

Upvotes: 1

Oliver Jonas
Oliver Jonas

Reputation: 1248

I've not used this myself but try https://github.com/MeetMe/Android-HorizontalListView

Unlike HorizontalScrollView this works with ListAdapters just like the traditional vertical ListView does.

Upvotes: 0

Related Questions