I state that i'm not very experienced in android, and I would like to understand, perhaps with some tutorial, how to implement any scrolling animation between one activity and another. I hope in your help
Asked
Active
Viewed 1.8k times
1 Answers
25
You can set up animations (like slide) when you switch between activities like this :
In the res
folder, create an anim
folder
For example, put two xml
files for a slide effect :
slide_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"/>
</set>
slide_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200" />
</set>
Then on your java code just write this :
Intent i = new Intent(YourActivity.this, OtherActivity.class);
this.startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
If you are testing that on a real device, don't forget to allow it to play animations (Settings -> Display -> Animations -> All Animations)
Hope it helps ! :)

Alexis C.
- 91,686
- 21
- 171
- 177
-
1thanks for the advice, I'm testing, but I have a small problem, the transition from one activity to another is after pressing a button and I have do "finish();" on the activity starting – user1480020 Aug 23 '12 at 14:04
-
Which activity do you want to finish ? The first one ? – Alexis C. Aug 23 '12 at 14:05
-
I edited my answer. Is it working like you want now ? – Alexis C. Aug 23 '12 at 14:13
-
Now the activity is not even started – user1480020 Aug 23 '12 at 14:22
-
the first activity don't start – user1480020 Aug 23 '12 at 14:24
-
Please put the code of the button event. – Alexis C. Aug 23 '12 at 14:25
-
But If you call finish() on your first activity, it destroys it. – Alexis C. Aug 23 '12 at 14:25
-
In fact, I have to destroy the first activated and move to the second – user1480020 Aug 23 '12 at 14:27
-
If you call finish() on your first activity, you won't be able to start it a second time. Finish : `Call this when your activity is done and should be closed`. See this http://developer.android.com/reference/android/app/Activity.html and this http://developer.android.com/images/activity_lifecycle.png to understand how activities works. – Alexis C. Aug 23 '12 at 14:33
-
I added the above code but by second activity is not displaying. :( – Si8 Jul 25 '13 at 15:22
-
@SiKni8 Any error in logcat ? – Alexis C. Jul 26 '13 at 12:23
-
Do we have to have a Material Theme in our styles.xml? Or at least be using API 21 or higher? – Azurespot May 16 '16 at 01:32