Reputation: 848
I read the below link before posting this.
How to apply slide animation between two activities in Android?
I need to know how to make activity slideup xml animation. like what they have done for fadein and fadeout.
Upvotes: 19
Views: 34926
Reputation: 232
You can use below code for slide up activity transition animation.
startActivity(new Intent(MainActivity.this, DataSetActivity.class));
overridePendingTransition(R.anim.slide_out_bottom, R.anim.slide_in_bottom);
R.anim.slide_out_bottom
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="250"
android:fromXDelta="0%"
android:fromYDelta="100%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
R.anim.slide_in_bottom
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="100%" />
</set>
Upvotes: 0
Reputation: 1949
for slide_in xml :
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="250"
android:fromXDelta="-100%p"
android:toXDelta="0%p">
</translate>
for slide_out xml:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXDelta="0"
android:toXDelta="100%p">
</translate>
Java code :
Intent intent = new Intent(this, newActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
put both xml files in res/anim folder.
Upvotes: 35
Reputation: 23381
The accepted answer isn't what the question was asking, which is animations that slide up from the bottom and slide out from the top.
pull_up_from_bottom.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:fromYDelta="100%"
android:toYDelta="0%" />
push_out_to_bottom.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:fromYDelta="0%"
android:toYDelta="100%" />
Upvotes: 61
Reputation: 11731
This is what I was after:
res/anim/slide_up.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="100%"
android:toYDelta="0%" />
res/anim/slide_down.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />
res/anim/slide_down_reverse.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />
res/anim/slide_up_reverse.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="100%" />
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.your_layout)
overridePendingTransition(R.anim.slide_up, R.anim.slide_down)
}
override fun finish() {
super.finish()
overridePendingTransition(R.anim.slide_down_reverse, R.anim.slide_up_reverse)
}
Upvotes: 7