Android Slide in and out animation issue

故事扮演 提交于 2020-01-12 10:45:11

问题


My Activity Successfully slide in android 4.1 from Activity A to B using animation

**inamation.xml**

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="600" />
</set>

and

outanimation.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="600" />
</set>

and in activity A i used overidding pending transition as shown below:

A.this.overridePendingTransition(R.anim.outanimation,R.anim.inanimation);

as said earlier this works fine on android 4 and above platform but when i test it on android 2.3 platform, Activity A to B gets android default activity animation.

how can i run my activity to slide left to right and right to left which is compatible with 2.2 and above.

Is there a way to set animation between two activities programmatically ?

UPDATE

The problem was that the device, at least in the case of Samsung Galaxy, has to have animations enabled for this to work. This can be done in the settings menu.

Do you know how to activate all animation from settings Menu in Android ?


回答1:


For Android Slide in and out animation, I have use following code.

Activity A :

Intent intnt = new Intent(SplashScreen.this,
                        CustomTabActivity.class);
                startActivity(intnt);
                overridePendingTransition(R.anim.slide_in_left,
                        R.anim.slide_out_left);
                finish();

slide_in_left.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromXDelta="100%p"
    android:toXDelta="0%p" />

slide_out_left.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromXDelta="0"
    android:toXDelta="-100%p" />


来源:https://stackoverflow.com/questions/16477027/android-slide-in-and-out-animation-issue

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