0

At the moment, I am using a ScrollView with a LinearLayout inside it. I want to implement a snap function. Am I better off using a ListView? Is it even possible to implement a snap function with my current setup? I want to keep things simple.

user1923613
  • 626
  • 5
  • 11
  • 31
  • 3
    What is a _snap function_? – K-ballo Jan 06 '13 at 23:20
  • Kinda hard to explain: better to watch [this](http://www.youtube.com/watch?v=q4oOwMZ8BBY). Notice that the items always "snap" to the center. If those were images, you don't get partially-showing pictures. – user1923613 Jan 06 '13 at 23:27

1 Answers1

1

By "snap function" I am assuming that you mean paging so the user can swipe from side to side similar to the Play Store or the ICS Dialer apps. While yes, you can implement this yourself with a ScrollView, or any number of other solutions, I don't think you should because you can use Android's ViewPager class.

ViewPager is a wonderful view that uses a collection of Fragments as pages in a single layout. This will give your user a very familiar and consistent interface, and will save you a lot of very difficult code.

mtmurdock
  • 12,756
  • 21
  • 65
  • 108
  • I'd like to be able to show more than one item at a time. Can you do that in a ViewPager? The items will just have to snap to the left/top of the screen. – user1923613 Jan 06 '13 at 23:36
  • You can override the getPageWidth method in FragmentPagerAdapter to display multiple fragments at the same time. See this: http://stackoverflow.com/questions/9693836/fragmentpageradapter-swipe-to-show-listview-1-3-screen-width – Victor KP Jan 06 '13 at 23:49
  • Wow! Looks like that will do the job. Thanks guys! – user1923613 Jan 07 '13 at 00:08