In certain cases it is required to open the activity with transition like from left-to-right or top-to bottom or vice-versa.
For this we have to create xml file that must be kept in "anim" folder.
Regarding xml, we have 4 different attributes:-
1)for vertical transition
android:fromYDelta
android:toYDelta
2) for horizontal transition
android:fromXDelta
android:toXDelta
xml 1(a) :- left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>
</set>
xml 1(b) :- left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"/>
</set>
xml 2(a) :- right_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="500"/>
</set>
xml 2(b) :- right_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"/>
</set>
xml 3(a) :- down_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="500"/>
</set>
xml 1(b) :-down_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="500"/>
</set>
xml 4(a) :- up_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="-100%p"
android:toYDelta="0"
android:duration="500"/>
</set>
xml 4(b) :-up_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:duration="500"/>
</set>
Now when you open the activity use "overridePendingTransition" and set the transitions as given according to your re requirement:-
Intent intent = new Intent(this, yourclass.class);
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
startActivity(intent);
0 Comment(s)