I am trying to animate the way a new Activity appears. Default is to slide in. I have an animation set that I would like to somehow append to the Intent or the Activity so that it will start when I call startActivity.
The catch is that I need to do this completely programmatically. I cannot declare any XML resources for animations, etc. How would I do this?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken button to show /hide linear layout with animation.
Here is some code snippet
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
slide_in_right
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
slide_out_left
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
You can tiker with the codes to get your desire effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With