简体   繁体   English

Android活动过渡动画

[英]Android Activity Transition Animation

What I am trying to achieve is : start a new activity with a transition animation for the exiting activity only . 我想要实现的是: 针对退出活动启动带有过渡动画的新活动。

I would like to slide up the current activity, where the new activity will be behind the current one. 我想升级当前活动,新活动将落后于当前活动。

Here is the slide up animation : R.layout.slide_up 这是滑动动画: R.layout.slide_up

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="1000"
        android:fromYDelta="0%"
        android:toYDelta="100%" />

</set>

Here is how I am applying the activity animation transition : 以下是我应用活动动画过渡的方法:

overridePendingTransition ( 0 , R.anim.slide_up );

I am using 0 for the entering activity since I do not want any animation for the new activity, and it is not working (the animation is not performed). 我正在使用0进行输入活动,因为我不想为新活动添加任何动画,并且它不起作用(不执行动画)。 If I use an animation for entering activity too, it works (both animations are performed), like such : 如果我也使用动画来输入活动,它可以工作(两个动画都会执行),如下所示:

overridePendingTransition ( R.anim.slide_out , R.anim.slide_up );

where R.anim.slide_out : 其中R.anim.slide_out

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="1000"
        android:fromYDelta="100%"
        android:toYDelta="0%" />

</set>

Any ideas ? 有任何想法吗 ?

I am working on Android 4.1.2 and Android 4.0.4 我正在使用Android 4.1.2和Android 4.0.4

Alter your exit animation so that it renders over top of the entering activity. 更改退出动画,使其呈现在输入活动的顶部。

R.anim.slide_up R.anim.slide_up

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:zAdjustment="top">

    <translate
        android:duration="1000"
        android:fromYDelta="0%"
        android:toYDelta="100%" />

</set>

Then you can do what you were originally doing to set the animation. 然后你可以做你最初做的设置动画。

overridePendingTransition ( 0 , R.anim.slide_up );

I have exactly the same transition and such animation works for me: 我有完全相同的过渡,这样的动画对我有用:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromYDelta="0%" android:toYDelta="100%" android:zAdjustment="top"
android:duration="300" />  

Call the below method after startActivity method. 在startActivity方法之后调用以下方法。

 overridePendingTransition(0,0);

This will override the default animation and do no animation. 这将覆盖默认动画并且不执行动画。 You can also give some custom animation if you like 如果您愿意,也可以提供一些自定义动画

overridePendingTransition(R.anim.animation1,R.anim.animation2); overridePendingTransition(R.anim.animation1,R.anim.animation2);

Wherever you are calling the intent to start the Activity, you need to modify the intent. 无论您在何处调用启动Activity的意图,都需要修改意图。 ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(AlbumListActivity.this); startActivity(intent, options.toBundle());

If you have any dedicated method to setupTransitions() You can put the next two lines of code there, Else you may put them in onCreate() 如果你有任何专门的setupTransitions()方法setupTransitions()你可以将接下来的两行代码放在那里,否则你可以把它们放在onCreate()

getWindow().setEnterTransition(new Slide(Gravity.RIGHT).setDuration(800));

Gravity.RIGHT is what determines the direction from which you want to start your next Activity. Gravity.RIGHT决定了你想要开始下一个Activity的方向。 setDuration() method is optional, for smoother Transition I used it, You don't have to. setDuration()方法是可选的,为了更平滑过渡,我使用它,你不必。

Explore more by playing around with different Gravity and setDuration Properties. 通过使用不同的Gravity和setDuration属性来探索更多内容。

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

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