2

Possible Duplicate:
Android - Can View Pager have multiple views in per page?

I'm using ViewPager according to this wonderful tutorial:

http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/

This tutorial shows how to display only one "page" or view in every time/swip.

How can I make something like the strip in Pulse app:

enter image description here

That have the snapping effect like ViewPager but can have multiple views inside?

Community
  • 1
  • 1
David
  • 37,109
  • 32
  • 120
  • 141

2 Answers2

2

It seems like the view pager only does one view at a time and can't have multiple views.

You can try to implement your own horizontal scroll view with your own fling and touch methods: http://blog.velir.com/index.php/2010/11/17/android-snapping-horizontal-scroll/

Or you can extend a Gallery which I think is what Pulse app is doing. Notice the snapping to position similarity of each item with the Gallery.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
CLDev
  • 1,076
  • 3
  • 12
  • 20
  • So actually what are the differences between gallery and Horizontal scroll view with fling and touch methods? Why not using gallery anyway? – David Feb 28 '12 at 08:45
  • 1
    Gallery comes prebuilt with fling and touch methods but has a feature of snapping to the center upon click. If that is not an issue, then definitely use the gallery. Horizontal Scroll View, you would have to implement your own fling and touch since is not prebuilt in. – CLDev Feb 28 '12 at 16:45
1

Using LayoutInflater you can do what ever you want inside instantiateItem

  1. Create the xml you need to view
  2. Get and instance of LayoutInflater and inflate that xml on the page(s) you want
  3. Inside instantiateItem do the changes to the inflated views by calling inflatedviewname.findviewbyid

Checkout this line in my project

Let me know in the comments if you still need help

EDIT:

Maybe forget about the viewpager and use a horizontalscrollview but be careful about the item count and how you load them as it may take lots of memory the horizontal scroll view does some optimizations but they are not as good as he viewpager

Community
  • 1
  • 1
Shereef Marzouk
  • 3,282
  • 7
  • 41
  • 64
  • I know I can add any view inside one page of my ViewPager, but then this view (and all his subviews) acts like one page/chunk. You can't scroll to the middle of this view and stop there (the snapping will take you to right/left) – David Feb 27 '12 at 11:02
  • you can't have a horizontal scroll view in a viewpager but you can have a scroll view that scrolls vertically or an listview. – Shereef Marzouk Feb 27 '12 at 13:42
  • i recommend you use more pages to achieve your goal or elaborate more so we can help you find a solution,@David try the HorizontalScrollView Without a viewpager you will be able to make a scrolling strip without snapping – Shereef Marzouk Feb 27 '12 at 13:43
  • Thanks for advice. I tried HorizontalScrollView, It's ok. But can I have a HorizontalScrollView with snapping effect? That will be great! – David Feb 27 '12 at 14:35
  • @david i dont get it, if you need the snapping effect why not use more pages on a view pager instead of more views? – Shereef Marzouk Feb 27 '12 at 19:26
  • By saying "use more pages on a view pager" what do you mean? – David Feb 28 '12 at 00:16