How to get started with a set of animations fully programmatically

I am trying to revive the way a new Activity appears. The default for the slide. I have a set of animations that I would like to somehow add to Intent or Activity so that it starts when I call startActivity.

The trick is that I need to do this completely programmatically. I cannot declare any XML resources for animation, etc. How can I do it?

+8
android android-layout android-animation
source share
2 answers

Here is a snippet of code

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 dial codes to get the effect of desire.

+3
source share

Activity has an overridePendingTransition() method that can be used to transfer new animations. So you just call it in the onCreate your Activity .

0
source share

All Articles