Android Fade Out LinearLayout never starts

I am new to Android animation, and I seem to have a simple problem ... I have a splash / load screen that I want to turn off when this is done, and then show the application.

My layout looks something like this (styles just set the 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 and setting up the main screen:

 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 the startAnimation code, but the animation never starts, and I never get the onAnimationEnd () call. What did I forget to turn on to start the animation?

+6
source share
1 answer

I was a careless programmer.

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

should really read:

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

because the disappearance of something invisible is not what I intended.

+1
source

Source: https://habr.com/ru/post/924761/


All Articles