What is the default transition between activities in Android 4.0 (API 14+)

左心房为你撑大大i 提交于 2019-12-30 06:07:43

问题


I built an application with quite a few activities and I would like to have "slide from right on enter/slide from left on exit" transitions between them.

I read more than once that slide transitions should be the Android default, but on the device I am developing on the transitions are fade in/fade out by default (Galaxy Tab 2 7", on ICS 4.0).

Is there anything I need to declare at application level, for example in the manifest file?

I am asking because otherwise I would need to add overridePendingTransition (R.anim.right_slide_in, R.anim.left_slide_out); to all my transitions which are plenty...just wondering if I am missing something before going that road.

Many thanks


回答1:


No answers...on the devices 4+ I tried, the animation is a fade-in fade-out with zoom in or out...

I added the code manually where I wanted to have the slide animation:

//open activity
startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(R.anim.right_slide_in, R.anim.left_slide_out);

xml animation right to left:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator" >

<translate
    android:duration="300"
    android:fromXDelta="100%p"
    android:toXDelta="0" />

</set>

xml animation left to right:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator" >

<translate
    android:duration="300"
    android:fromXDelta="0"
    android:toXDelta="-100%p" />

</set>



回答2:


In your style.xml file put

 <style name="WindowAnimationTransition">
    <item name="android:windowEnterAnimation">@android:anim/slide_in_left</item>
    <item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
</style>

and add

 <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
   ...
    <item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
</style>



回答3:


There is a way which involves creating a style and then adding it in manifest here: How to change all the activity transitions at once in Android application?, yet I only managed to make it work over startActivity(). Whenever back is pressed this method won't work or I might just missing something.



来源:https://stackoverflow.com/questions/13856925/what-is-the-default-transition-between-activities-in-android-4-0-api-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!