Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Fade Out LinearLayout Never Starts

I am new to animations on Android and I seem to be having a simple issue... I have a splash/loading screen, which I want to fade out when it's done, then show the app.

My layout looks something like this (the styles just set a background image):

<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>

Then I tried two different approaches to fading the splash screen out and setting the main screen 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);

Then I tried my own animation:

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);

And I get to the startAnimation code, but the animation never seems to start, and I never get the onAnimationEnd() call. What have I forgotten to include to get the animation to actually run?

like image 856
xbakesx Avatar asked Sep 06 '12 16:09

xbakesx


1 Answers

I have been a careless programmer.

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

should actually read:

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

because fading out something that is invisible is not what I had intended.

like image 70
xbakesx Avatar answered Oct 22 '22 16:10

xbakesx