2011-03-05 12 views
6

Tuve una actividad (decir homeActivity) y cuando comienzo una nueva actividad (decir nextActivity) de mi homeactivity me gustaría darle un efecto de animación como aparecer desde la parte inferior. ¿Es posible en Android?animación en android

Respuesta

2

Puede evitar la animación predeterminada (deslizar desde la derecha) con el indicador Intent.FLAG_ACTIVITY_NO_ANIMATION en su intento.

es decir .:

Intent myIntent = new Intent(context, MyActivity.class); 
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
context.startActivity(myIntent); 

luego en su actividad simplemente tiene que especificar su propia animación.

6

después de llamar a startActivity, realice una llamada a overridePendingTransition con id de xml animaciones definidas, una para salir de la actividad, una para ingresar. Ver documentos para este método here

1
TopListActivity topList; 
Vector<BitmapDrawable> images; 
int count = 0; 
public AnimationAlphaTimer(TopListActivity _topList) 
{ 
    this.topList = _topList; 

    this.images = new Vector<BitmapDrawable>(); 
    for (int i = 0; ; i++) { 
    // LOAD IMAGES HERE 
    } 

    if (this.images.size() > 0) { 
    this.topList.slide_0.setBackgroundDrawable(this.images.get(0)); 

    if (this.images.size() > 1) { 
     this.topList.slide_1.setBackgroundDrawable(this.images.get(1)); 
    } 
    } 

    this.count = 1; 
} 

public void launch() 
{ 
    if (this.images.size() >= 2) { 
    (new Timer(false)).schedule(this, 100); 
    } 
} 

@Override 
public void run() 
{ 
    this.doit(); 
    this.cancel(); 
} 

private void doit() 
{ 
    if ((this.count % 2) == 0) { 
    AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f); 
    animation.setStartOffset(3000); 
    animation.setDuration(3000); 
    animation.setFillAfter(true); 
    animation.setAnimationListener(this); 

    this.topList.slide_1.startAnimation(animation); 
    } else { 
    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f); 
    animation.setStartOffset(3000); 
    animation.setDuration(3000); 
    animation.setFillAfter(true); 
    animation.setAnimationListener(this); 

    this.topList.slide_1.startAnimation(animation); 
    } 
} 

public void onAnimationEnd(Animation animation) 
{ 
    if ((this.count % 2) == 0) { 
    this.topList.slide_1.setBackgroundDrawable(
     this.images.get((this.count + 1) % (this.images.size())) 
    ); 
    } else { 
    this.topList.slide_0.setBackgroundDrawable(
     this.images.get((this.count + 1) % (this.images.size())) 
    ); 
    } 

    this.count++; 
    this.doit(); 
} 
public void onAnimationRepeat(Animation animation) { 
} 
public void onAnimationStart(Animation animation) { 
}} 

probar esto, creo que va a funcionar.