Tuesday, 24 November 2009

Android transitions, Views and Activities

When I talk about transitions in Android I'm referring to the Animations that link Views or Activities together. So when a user navigates from one View or Activity to another, they may see the present widgets slide to the left and the new ones slide in from the right, or the old widgets might fade out while the new ones fade in. In a post I wrote a while back I outlined how to implement a slide in slide out animation with Views, using the android ViewFlipper component and a number of translate animations. At the time I mentioned that this transitions animation was for views only and that there was a global control in the settings menu for enabling transitions for activities. At the time there did not seem to be a way of control the transitions for activities on a per Activity basis. That was back in Android 1.5, but since then things have move on some. With Android 2.0 it is now possible to control the transition animations for activities. These transitions can be enabled or disable on a per activity basis and it is also possible to set the in and out animation for each activity.

The first thing you need to know to override the activity transition is that there is a new function call in the Activity class called overridePendingTransistion. This function takes two arguments, the resource ID of the enter, or in, animation and the resource id of the exit, or out, animation. Also there is a new flag in the Intent class called FLAG_ACTIVITY_NO_ANIMATION, which gives control over which Activities transition Animations are shown.

So by using the new flag and the new function call it is now possible to control the transitions of your Activities in the same way as your Views. 

1 comment:

  1. Hi, how do you control the transitions speed in application?

    Jonathan Ng