I want one of my activites to come from the bottom of the screen when it starts and when it finishes I want it to dissapear back to the bottom. Is it possible to do it? And if yes - any idea how?
Thanks in advance.
I want one of my activites to come from the bottom of the screen when it starts and when it finishes I want it to dissapear back to the bottom. Is it possible to do it? And if yes - any idea how?
Thanks in advance.
I don't know how to change how an activity starts, but to make it close in a certain way, you can override the finish() method and add an animation.
you can call overridePendingTransition after startActivity() to change how the scene changes when you start a new activity.
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_bottom);
}
where slide_out_bottom comes in your Res\anim folder and could look like this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0"
android:toYDelta="100%p" />
</set>
This is altered code from a project, so you have to test it.
You should define two animations
: enter and exit for your activity
R.anim.enter
<?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%p"
android:toYDelta="0%p"/>
R.anim.exit
<?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%p"
android:toYDelta="100%p"/>
and use this anims in your activity
class TestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
overridePendingTransition(R.anim.enter, android.R.anim.fade_out)
}
override fun finish() {
super.finish()
overridePendingTransition(R.anim.exit, android.R.anim.fade_in)
}
override fun onBackPressed() {
finish()
}
}
you can call overridePendingTransition after startActivity() to change start a new activity animation.
try this line of code
slide_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
slide_to_right
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
MainActivity.java
startActivity(intent); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);