1

I am developing an android application. It uses Fragments. In first screen (Home.java), it has 5 buttons. Lets say button1, button2, button3, button4, button5. When you click button1, it should go to FragmentView1screen, when you click on button2 it should go to FragmentView2 screen and so on. These screens are FragmentActivities

Now, I need to add an animation which is similar to ViewPager, but, with a difference. ViewPager allows you to slide, but as you can see, that will not work here, because different buttons open different screens. In ViewPager it is not like that, you go to first screen, then slide and go to second, then to third etc. It is a sequence.

Here what I want is when you click on a button (only when click on a button), it should slide (just like ViewPager animation) to the particular screen. Now if the user slides back, it will come back to the Home.java screen (I don't know whether this part is possible, if not then let me know I can drop it). When he user click on the back button, it should slide back to the Home.java.

Some screens like FragmentView1 uses ViewPager by themselves to access their own sequence of pages so the above mechanism should not affect this.

How can I do something like this? I think you can see this in Yahoo mail app as well.

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • Have a look here: http://stackoverflow.com/questions/8876126/swap-fragment-in-an-activity-via-animation You'll want to use FragmentTransaction and add enter and exit animations for your fragments. It should be fairly straightforward – Entreco Jan 13 '14 at 08:55
  • @Entreco: It is not equal to the VoewPager animation isnt it? – PeakGen Jan 13 '14 at 09:10
  • 2
    you can use any animation you want, the example in the accepted answer uses slide_in_left and slide_out_right but you can modify it to match the viewpager animation. I believe the viewpager is usually slide_in_right, slide_out_left – Entreco Jan 13 '14 at 10:00
  • @Entreco, yes that's absolutely right. GloryOfSuccess, just don't think of ViewPager, use fragment transition and you will get what you want. – djhs16 Jan 27 '14 at 20:53
  • 1
    Hi PeakGen, would you respond to @Nick please? This could do with an answer. Do note that this site is powered by goodwill as well as gamification, and it is normally considered polite to respond in a timely fashion to helpful people. – halfer Oct 17 '17 at 09:33

1 Answers1

1

You can do this with a view pager and it's pretty simple, you just have to implement your 'tab' buttons yourself then make their click actions call viewPager.setCurrentItem();

The benefit to this method is that you are using the default view pager so you get the default animation and it scrolls smoothly between and initialised the fragments. This will of course leave the pager open to being scrolled directly.

Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124