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

然后,我尝试了两种不同的方法来淡出初始屏幕并将主屏幕设置为可见:
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);

然后我尝试了自己的动画:
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);

而且我进入了startAnimation代码,但是动画似乎从未开始,并且也从未获得过onAnimationEnd()调用。我忘了包括什么才能使动画真正运行?

最佳答案

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

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

实际上应该阅读:
final View splash = findViewById(R.id.homeSplashLayout);

因为淡出一些看不见的东西不是我想要的。

09-10 02:20
查看更多