Android淡出LinearLayout永远不会启动

xba*_*esx 6 android fadeout android-animation

我是Android新动画的新手,我似乎有一个简单的问题......我有一个启动/加载屏幕,我想在完成时淡出,然后显示应用程序.

我的布局看起来像这样(样式只是设置一个背景图像):

<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>
Run Code Online (Sandbox Code Playgroud)

然后我尝试了两种不同的方法来淡出启动画面并设置主屏幕:

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);
Run Code Online (Sandbox Code Playgroud)

然后我尝试了自己的动画:

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);
Run Code Online (Sandbox Code Playgroud)

我得到了startAnimation代码,但动画似乎永远不会启动,我从来没有得到onAnimationEnd()调用.为了让动画真正运行,我忘了包括什么?

xba*_*esx 1

我曾经是一个粗心的程序员。

final View splash = findViewById(R.id.homeMainLayout);
Run Code Online (Sandbox Code Playgroud)

实际上应该读:

final View splash = findViewById(R.id.homeSplashLayout);
Run Code Online (Sandbox Code Playgroud)

因为淡出一些看不见的东西并不是我的初衷。