简体   繁体   English

在活动之间切换的动画

[英]Animation for switching between Activities

Ok I have a Problem. 好的,我有问题。 I implemented a SlideMenu with jfeinstein10's Library. 我用jfeinstein10的Library实现了SlideMenu。 I'm switching between the different items (all FragmentActivities) with startActivity() and Intents. 我正在使用startActivity()和Intents在不同的项目(所有FragmentActivities)之间切换。 For the normal Transition I'm using overridePendingTransition. 对于普通的Transition,我使用了overridePendingTransition。 Nearly all Activities are ViewPagers with TabPageIndicator from Jake Wharton. 几乎所有的活动都是来自Jake Wharton的带有TabPageIndicator的ViewPagers。

The thing is I'm using a custom layout (Google Now card style) with animations. 问题是我正在使用带有动画的自定义布局(Google即时贴样式)。 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. 我扩展了LinearLayout,对于动画,我遍历了子级(卡片)并为每个子级开始动画。 The cards are RelativeLayouts added to the custom LinearLayout. 这些卡是添加到自定义LinearLayout中的RelativeLayouts。

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. 我的想法是,启动应用程序后,卡片从buttom(类似于Google Now)向上滑动,当我将“活动”从当前“活动”切换为“向下”时,现在空白的“活动”会淡入淡出(通过overridePendingTransition)切换到新的“活动”并且新“活动”中的即时贴会向上滑动。

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). 我尝试将onGlobalLayoutListener用于向上滑动的东西,但这在ViewPager中表现得很奇怪(第一个选项卡向上滑动,第二个选项卡向上滑动,第三个选项卡向上滑动)。 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. 我尝试在自定义布局中创建其他方法,并以onPause()开头-根本无法正常工作。

So I wanted to ask if anyone got a idea? 所以我想问问是否有人有想法? Or is this possible at all? 还是有可能吗? This problem really drives me crazy :D 这个问题真的让我发疯:D

Edit: 编辑:

http://pastebin.com/8mDefv50 My NowLayout http://pastebin.com/8mDefv50我的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). 这个https://github.com/jfeinstein10/SlidingMenu/blob/master/example/src/com/slidingmenu/example/fragments/ResponsiveUIActivity.java基本上是我的基本ui(与content_frame相同的方法,并检查menu_frame)。 The Menu itself contains a few buttons which start the different FragmentActivities. 菜单本身包含一些按钮,用于启动不同的FragmentActivities。

The FragmentActivities only manage the ViewPager. FragmentActivities仅管理ViewPager。 The real content and NowLayout is used in the Fragment for the ViewPager. 实际内容和NowLayout用于ViewPager的Fragment中。

So my problem is to access the animation in the MenuFragment in a nice way. 所以我的问题是以一种很好的方式访问MenuFragment中的动画。 Mostly getting NPE because the switch is done in the MenuFragment which only holds the buttons. 大多数情况下会获得NPE,因为切换是在仅包含按钮的MenuFragment中完成的。 Maybe I'm slow on the uptake or I'm missing the forest for the trees :D 也许我吸收缓慢,或者我想念树木的森林:D

The slide down animation you should execute BEFORE calling the Intent for the new activity - not on onPause() since it's too late. 您应该在调用新活动的Intent之前执行下滑动画,而不是在onPause()上调用,因为为时已晚。

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. 因此,当您需要从当前Activity前进或后退时,请执行向下滑动的动画,在此动画的末尾放置一个侦听器,然后根据需要执行finish()/ startActivity()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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