Viewpager with multiple views inside like “Pulse” app strip [duplicate]

心不动则不痛 提交于 2019-12-22 17:52:17

问题


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:

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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/9458272/viewpager-with-multiple-views-inside-like-pulse-app-strip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!