Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ICS Activity Transition from Fade In/Out Back to Slide

I have an app where I used default slide in/out effects on standards activities and fade in/out on a few specific activities.

I've noticed that the new Android 4.X (ICS) has a different default, which is exactly fade in/out.

How can i define on my standard activities my slide in/out effect?

I've been trying to define it with:

@Override
public void onCreate(Bundle savedInstanceState)
{
    this.overridePendingTransition(0, android.R.anim.slide_in_left);                  
    super.onCreate(savedInstanceState);
}

@Override
public void onPause()
{
    super.onPause();
    overridePendingTransition(android.R.anim.slide_out_right, 0);
}

To reproduce the fade in / out effect i'm using:

@Override
public void onCreate(Bundle savedInstanceState)
{
    this.overridePendingTransition(0, android.R.anim.fade_in);                  
    super.onCreate(savedInstanceState);
}

@Override
public void onPause()
{
    super.onPause();
    overridePendingTransition(android.R.anim.fade_in, 0);
}

but haven't managed to successfully reproduce it.

Also, I'm using this code on onCreate and onPause, is this correct? Or is there a better place to put it?

Thanks

PS: I've seen this New Android 4.0 Screen Transitions Between Activities but now answer has been provided.

like image 409
neteinstein Avatar asked Apr 11 '12 14:04

neteinstein


1 Answers

overridePendingTransition() has to be called immediately after starting the new activity, so you would call it after startActivity(intent), for example. To make a default you can create a class that extends Activity and override startActivity, onBackPressed(), etc. to override the transition. For example:

public class MyActivity extends Activity {

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.slide_in_transition,R.anim.slide_out_transition);
}

@Override
public void startActivity(Intent intent) {
    super.startActivity(intent);
    overridePendingTransition(R.anim.slide_in_transition,R.anim.slide_out_transition);
}

@Override
public void finish() {
    super.finish();
    overridePendingTransition(R.anim.slide_in_transition,R.anim.slide_out_transition);
}



}

Then, just extend MyActivity instead of Activity in your activities and the transitions should all be sliding by default.

like image 158
Jens Zalzala Avatar answered Sep 27 '22 19:09

Jens Zalzala