简体   繁体   中英

Animation for switching between Activities

Ok I have a Problem. I implemented a SlideMenu with jfeinstein10's Library. I'm switching between the different items (all FragmentActivities) with startActivity() and Intents. For the normal Transition I'm using overridePendingTransition. Nearly all Activities are ViewPagers with TabPageIndicator from Jake Wharton.

The thing is I'm using a custom layout (Google Now card style) with animations. One slide up and one slide down animation. I extended LinearLayout and for for the animations I loop through the childs (cards) and start the animation for each child. The cards are RelativeLayouts added to the custom LinearLayout.

My idea was that after starting the app the cards slide up from buttom (Google Now like) and when I switch Activities the cards from the current Activity slide down, then the now blank Activity switches to the new Activity with a fade (via overridePendingTransition) and the cards from the new Activity slide up.

I tried to use a onGlobalLayoutListener for the slide up stuff, but this behaves weird in the ViewPager (The first tab slides up, the second stays the way and the third slides up too). The Animation should only appear after starting the app or switching between the Activities.

For the slide down animation I have no clue at all. I tried creating a additional method in my custom layout and starting it with onPause() - not working at all.

So I wanted to ask if anyone got a idea? Or is this possible at all? This problem really drives me crazy :D

Edit:

http://pastebin.com/8mDefv50 My NowLayout

and this https://github.com/jfeinstein10/SlidingMenu/blob/master/example/src/com/slidingmenu/example/fragments/ResponsiveUIActivity.java is basically my base ui (Same method with the content_frame and check for menu_frame). The Menu itself contains a few buttons which start the different FragmentActivities.

The FragmentActivities only manage the ViewPager. The real content and NowLayout is used in the Fragment for the ViewPager.

So my problem is to access the animation in the MenuFragment in a nice way. Mostly getting NPE because the switch is done in the MenuFragment which only holds the buttons. Maybe I'm slow on the uptake or I'm missing the forest for the trees :D

The slide down animation you should execute BEFORE calling the Intent for the new activity - not on onPause() since it's too late.

So when you need to go forward or backward from the current Activity - perform the slide down animation, put a listener on this animation's end and only then do the finish() / startActivity() as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM