How to make an Android view that flips between views on swipe/fling

谁说我不能喝 提交于 2019-12-17 06:27:11

问题


I'd like to make a view in my Android app that flips between multiple views on a swipe/fling. I'd like it to behave more or less like the Android Launcher behaves when flipping between views. In particular,

  1. It should flip views on swipe.
  2. Generally a swipe will flip between one view and the next. It should not fling across all of the views.
  3. If you swipe slowly, you should see the views dragging as you're swiping, eg. the way the Launcher does it.

I tried using a ViewFlipper with a GestureOverlayView as per Romain Guy's blog post here, but there's no indicator to the user as they're swiping. This makes discoverability difficult, which is presumably why Launcher does it the way they do.

I tried using a Gallery object, but when I swipe from left to right, there's a certain amount of momentum that flings the users through all the views rather than just taking them to the next view.

Is there a good way to accomplish what I'm trying to do?


回答1:


I know this is an old question but ViewPager is created for this exact same purpose. ViewPager is part of android compatibility package and more can be found at http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html




回答2:


Take a look at HorizontalPager. It's actually based on RealViewSwitcher, which in turn is based on the Android homescreen's code, and supports snap-to paging with drag feedback, as well as nested vertically-scrolling subviews. Gesture support for fast swipes isn't all it should be, but this may get you part of the way there (and I'd welcome contributions back).

EDIT: As of 2012 you're much better off using Google's ViewPager - it's in the compat library.




回答3:


Check out SwipeView within this project https://github.com/fry15/uk.co.jasonfry.android.tools It does exactly what you want it to do and is super simple to implement.




回答4:


@CommonsGuy extended ViewFlipper to do it. https://github.com/commonsguy/cwac-viewswiper Ihaven't used this one yet so im not sure if it moves with your finger like the launcher if not your going to have to make an OnTochListener to do it for you in me.ACTION_MOVE you will update the view to change its position. I'll post some sample code when I get home if you don't get another answer.



来源:https://stackoverflow.com/questions/5071743/how-to-make-an-android-view-that-flips-between-views-on-swipe-fling

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