Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start an Activity with an animation set entirely programmatically [closed]

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?

like image 456
user438293456 Avatar asked Mar 16 '12 18:03

user438293456


People also ask

How do you show and hide a view with a slide up down animation Android?

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.


1 Answers

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.

like image 128
Win Myo Htet Avatar answered Oct 14 '22 06:10

Win Myo Htet