How can I make my page slide as the user slides finger on the screen?

亡梦爱人 提交于 2019-11-27 17:13:19

Check out this tutorial and its follow up on warriorpoint. They explain how to use the ViewFlipper to smoothly animate the transition from one screen to another, and then in the second part how to do this using touch control. Note, these are whole-screen transitions not panning around on an existing page. For panning, e.g. on an oversized image that doesn't fit in the screen, check out Android BigImage. Depending on what you're trying to do these might be overkill, but it's not 100% clear what you're trying to achieve.

Bob

ViewPager. This would seem to have been addressed more completely after the fact:

Whether you have just started out in Android app development or are a veteran of the craft, it probably won’t be too long before you’ll need to implement horizontally scrolling sets of views. Many existing Android apps already use this UI pattern, such as the new Android Market, Google Docs and Google+. ViewPager standardizes the implementation.

The Home screen is made of two layers:

  • The background (or Workspace) that shows the image; this layer scrolls and draws the wallpaper with a different scroll value. Workspace behaves more or less like a simplified horizontal layout

  • The screens (or CellLayouts) that display the icons; this layer is made of 3 CellLayout side by side. CellLayout is a custom grid-like layout.

The fling is implemented using a VelocityTracker, a Scroller and regular View.scroll methods.

use gallery view

You will need Gesture detector - the classes / interfaces under considerations are:

 1. android.view.GestureDetector
 2. android.view.GestureDetector.SimpleOnGestureListener

Method of interest is onFling.

Now, based on the X, Y and the velocity in respective directions, you can "draw your view" / "reposition the nested views in case of activity or view-group" at corresponding location.

An example of how to redraw can be found in any game-example like LunarLander in Android at http://developer.android.com/resources/samples/LunarLander/src/com/example/android/lunarlander/LunarView.html

MrCloister

I did this for my application, Just thought I'd share my solution.

Android Homescreen

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