2012-09-06 9 views
6

Soy nuevo en las animaciones de Android y parece que tengo un problema simple ... Tengo una pantalla de inicio/carga, que quiero atenuar cuando termina y mostrar la aplicación .Desvanecimiento de Android LinearLayout Never Starts

Mi diseño se ve algo como esto (los estilos acaba de establecer una imagen de fondo):

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/homeParentContainer" 
    style="@style/LayoutWithBgStyle" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/homeSplashLayout" 
     style="@style/LayoutWithSplashStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/homeMainLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" 
     android:visibility="gone" > 
    </LinearLayout> 
</RelativeLayout> 

Luego he intentado dos enfoques diferentes a la decoloración de la pantalla de presentación y configuración de la pantalla principal visible:

final Animation fadeOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); 
final View splash = findViewById(R.id.homeMainLayout); 
fadeOut.setAnimationListener(new AnimationAdapter() 
{ 
    @Override 
    public void onAnimationEnd(final Animation animation) 
    { 
     splash.setVisibility(View.GONE); 
     findViewById(R.id.homeMainLayout).setVisibility(View.VISIBLE); 
    } 

    /** And the other two methods */ 

}); 
splash.startAnimation(fadeOut); 

Luego probé mi propia animación:

final AlphaAnimation fadeOut = new AlphaAnimation(1.0F, 0.0F); 
fadeOut.setDuration(1000); 
final View splash = findViewById(R.id.homeMainLayout); 
fadeOut.setAnimationListener(new AnimationListener() 
{ 
    @Override 
    public void onAnimationEnd(final Animation animation) 
    { 
     splash.setVisibility(View.GONE); 
     findViewById(R.id.homeMainLayout).setVisibility(View.VISIBLE); 
    } 

    /** And the other two methods */ 

}); 
splash.startAnimation(fadeOut); 

Y llego a la start Código de animación, pero la animación nunca parece comenzar, y nunca recibo la llamada onAnimationEnd(). ¿Qué he olvidado incluir para que la animación realmente se ejecute?

Respuesta

1

He sido un programador descuidado.

final View splash = findViewById(R.id.homeMainLayout); 

realidad debería decir:

final View splash = findViewById(R.id.homeSplashLayout); 

porque desvanecimiento algo que es invisible no es lo que había previsto.

Cuestiones relacionadas