Android过渡动画无效

时间:2015-03-24 23:10:56

标签: android android-animation android-5.0-lollipop android-transitions

Android的过渡与爆炸和幻灯片是一样的。实际上我不认为它的动画效果。持续时间不是6秒。我该如何解决?

代码取自here

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

        Transition ts = new Slide();  //Slide(); //Explode();

        ts.setDuration(6000);
        getWindow().setEnterTransition( ts );
        getWindow().setExitTransition( ts );
        setContentView(R.layout.activity_main_activity);



    }




    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finishAfterTransition();
    }

样式-v21.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="BaseAppTheme" parent="android:Theme.Material.Light">
        <item name="android:colorControlHighlight">#0000AA</item>
        <item name="android:navigationBarColor">#0000AA</item>
        <item name="android:colorPrimaryDark">#0000AA</item>
        <item name="android:colorPrimary">#0000FF</item>
        <item name="android:colorAccent">#00FF00</item>
        <item name="android:windowBackground">@android:color/black</item>
        <item name="android:textColorPrimary">@android:color/white</item>

        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>

        <!-- specify enter and exit transitions -->
        <item name="android:windowEnterTransition">@transition/explode</item>
        <item name="android:windowExitTransition">@transition/explode</item>
    </style>
</resources>

4 个答案:

答案 0 :(得分:13)

在我自己的情况下,出于某种原因,我在Android设备的开发者选项中关闭了Transition Animation。

  

只需转到设置 - &gt;开发者选项 - &gt;过渡动画   比例:设置为动画比例1x

答案 1 :(得分:4)

我发现我需要真正做到

ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, test, "transition_name");
ActivityCompat.startActivity(TourAndLoginActivity.this, new Intent(TourAndLoginActivity.this, LoginActivity.class), activityOptionsCompat.toBundle());

仍然令人费解,但我不知道为什么我们需要一个共享对象来进入/退出转换。如果我提供null而不是ActivityOptionsCompat,则没有转化

答案 2 :(得分:3)

请勿忘记在AndroidManifest.xml中为活动或整个套餐应用主题。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.package"
android:theme="@style/BaseAppTheme">
    ....
    ....
</manifest>

答案 3 :(得分:1)

您可以使用它来启动带有转换的新活动

startActivity(new Intent(this, NewActivity.class));
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);

创建文件res / anim / slide_in_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false" >
     <translate android:duration="1000" android:fromXDelta="100%" android:toXDelta="0%" />
    <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" />
</set>

创建文件res / anim / slide_out_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false" >
     <translate android:duration="2000" android:fromXDelta="0%" android:toXDelta="-100%"/>
     <alpha android:duration="2000" android:fromAlpha="1.0" android:toAlpha="0.0" />
</set>