【问题标题】:Android Fade Out LinearLayout Never StartsAndroid Fade Out LinearLayout 从不启动
【发布时间】:2012-09-07 00:48:49
【问题描述】:

我是 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() 调用。我忘记包含什么才能让动画真正运行?

【问题讨论】:

    标签: android android-animation fadeout


    【解决方案1】:

    我一直是个粗心的程序员。

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

    实际上应该是:

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

    因为淡出不可见的东西不是我的本意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-31
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      相关资源
      最近更新 更多