2

Hi i have a list of five activities and i want to intent from one page to another by animation , it will work for only two activities. If i swipe right to left in first screen it should go to second screen like wise if i swipe from right to left in second screen it should go to third activity and so on to fourth and fifth activity. Similarly if i swipe from left to right from fifth screen it should go on fourth and then third and then second and finally it should display first screen. Can anyone help me.

Thanks in advance

gkarthik
  • 131
  • 1
  • 2
  • 9
  • 1
    you want this perhaps http://code.google.com/p/andro-views/ or this http://developer.android.com/reference/android/support/v4/view/ViewPager.html – Sergey Benner Jan 27 '12 at 13:36

2 Answers2

2

Write your app using Fragments and use ViewPager to swipe between them.

HandlerExploit
  • 8,131
  • 4
  • 31
  • 50
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Lets assume that you don't want to use fragments. The doc says that its at its early stages, and will likely be changed. Whats a more solid way of doing it? – Andy May 23 '12 at 22:51
  • 1
    @Andy: "The doc says that its at its early stages, and will likely be changed" -- I have no idea what you are referring to. Fragments have been around for ~15 months. `ViewPager` has been around for ~12 months. They are being used for apps with massive distribution, such as the Play Store client: http://www.pushing-pixels.org/2012/03/16/responsive-mobile-design-on-android-from-view-pager-to-action-bar-tabs.html "Whats a more solid way of doing it?" -- there is no "more solid way of doing it". – CommonsWare May 23 '12 at 23:12
  • If thats the most popular way and recommended, then that is fine. Just wondering what other way there is to do it, but I appreciate the time taken to answer my question. – Andy May 23 '12 at 23:42
0

You can make use of gesture detector for this. A note worthy post on gesturedetector can be found here: http://androidcodelib.blogspot.in/2015/05/gesture-detector-sample-code.html

in on fling method of gesture detector just do the following modification for switching between activities. for eg for 5th activity the on fling function would be like this:

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX() < e2.getX()) //Left to Right swipe performed
 {
startActivity(new Intent(getApplicationContext(),activity4.class));
            }

if (e1.getX() > e2.getX()) //Right to Left swipe performed
 {
 finishAffinity(); 
            }
            return true;
}

you can refer this stackoverflow question for finding out how to add fadein animation for an activity:Fade in animation on Activity Transition

Community
  • 1
  • 1
visnkmr
  • 21
  • 5