6

I want to create a sort of card layout with cards that contain a ListView layout inside a HorizontalScrollableView that can scroll the cards horizontally. Everything is working but I have problem with scrolling. I can scroll the listview vertically only if I am not scrolling the cards horizontally and viceversa.

This is the main container:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <HorizontalScrollView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ddd" >

        <LinearLayout
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>



</RelativeLayout>

I inflate and add the listview items to the linear layout. I would like to allow vertical and horizontal scrolling smoothly without these kind of limitations (simultaneous horizontal and vertical scrolling).

How can I achieve this?

Matroska
  • 6,885
  • 14
  • 63
  • 99
  • So you want to scroll the entire listview horizontally or just the rows in the listview?? – Frank Sposaro Jun 27 '12 at 20:39
  • I want to scroll the list vertically and the cards that contain the list horizontally. I can do that but I cannot simoultaneously scroll so it is very difficult to achieve a good result – Matroska Jun 27 '12 at 20:42
  • You mean, you want a diagonal gesture to simultaneously scroll both the container and the listview - like, move your finger up and right and make scrollview scroll right and listview scroll up at the same time? – Ivan Bartsov Jul 02 '12 at 13:18
  • yes, I have found a question on stackoverflow about overriding HorizontalScrollView and method onInterceptTouchEvent. I can improve the behaviour but it isn't still optimal – Matroska Jul 02 '12 at 13:33
  • Does it not scroll smooth enough? This seems a very cpu-intensive task, are you using hardwareAccelerated flag in your manifest? On latest devices it makes huge difference for scrolling widgets, I once had to implement a ui for Xoom that had 15 ListViews in a horizontal scrollview (no requirement for simultaneous scrolling, though) - it was incredibly slow until i figured out how to turn on hardware rendering – Ivan Bartsov Jul 02 '12 at 19:42
  • Romain Guy works in Android team, he [suggested](http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing#comment3653232_3496042) not to place ListView inside a ScrollView. –  Jul 03 '12 at 11:32
  • Yes, it's generally a bad idea to have nested scrollables, but there are situations when it's absolutely necessary - like, when customer wants a certain complex design. – Ivan Bartsov Jul 09 '12 at 04:35

3 Answers3

2

Check out this, might help you implement custom two-way scrolling layout.

https://github.com/ened/Android-Tiling-ScrollView/blob/master/src/asia/ivity/android/tiledscrollview/TwoDScrollView.java

If you want any of ListView features though (like view recycling, filtering, adapters) - things are going to get more complicated.

Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
1

I would suggest you to take ViewFlipper to give scroll effect horizontally. Then add ListView to flipper as a child. Use gesture to move it right and left.

ListView will still scroll vertically and if you are not able to set OnItemClickListener to ListView then you can use SingleTap method of Gesture.

ListView inside View flipper discussion 1 and ListView inside View Flipper Discussio 2

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
0

I would suggest having your horiziontallayout as the root view you return in getView() in you adapter. That way each row will scroll separate from each other. If that doesn't work right away you may have to setItemsCanFocus(true) for your rows to give the input to your horizontalscrollview.

Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
  • no but the problem is that I don't want to horizontally scroll the listview elements but the cards because they are many and I want to see them all. So if [ and ] represent screen size and | is a card/listview, this is what I have: [| | | |]| | | | so the horizontal scroll is to watch cards. – Matroska Jun 27 '12 at 20:52