【问题标题】:fade in\out works too short and too fast in android淡入\淡出在android中工作太短太快
【发布时间】:2013-10-30 10:55:28
【问题描述】:

我正在尝试在 Android 中应用淡入\淡出过渡。

你能告诉我为什么我只看到褪色片刻,然后又恢复到原始 alpha 吗?

我已添加setFillAfter(true); 以保持图像消失。

我试过了:

                animation = android.view.animation.AnimationUtils
                        .loadAnimation(AppService.getAppContext(),
                                com.waze.R.anim.fade_out);

                animation.setInterpolator(new AccelerateInterpolator());
                animation.setFillAfter(true);
                boxImage_left.startAnimation(animation);

用这个:

<set xmlns:android="http://schemas.android.com/apk/res/android"
           android:fillAfter="true">
  <alpha android:fromAlpha="0.0"
         android:toAlpha="1.0"
         android:repeatCount="0"
         android:duration="500"/>
</set>

还有:

                AlphaAnimation alpha = new AlphaAnimation(0,1);
                alpha.setDuration(600);
                animation.setInterpolator(new AccelerateInterpolator());
                animation.setFillAfter(true);
                vImage_left.startAnimation(alpha); 

【问题讨论】:

    标签: java android xml eclipse animation


    【解决方案1】:

    让你的activity实现AnimationListener,设置动画结束后的可见性。

    public class YourActivity extends Activity implements AnimationListener
    {
        @override
        onCreate(Bundle x)
        {
            ...
            // set animation listener
            animFadein.setAnimationListener(this);
            animFadeOut.setAnimationListener(this);
    
        }
        @Override
        public void onAnimationEnd(Animation animation)
        {
            if (animation == animFadein)
            {
                view.setVisibility(View.VISIBLE);
            }
             if (animation == animFadeOut)
            {
                view.setVisibility(View.INVISIBLE);
            }
        }
    }
    

    为了动画速度修改动画持续时间和插值器

    【讨论】:

      【解决方案2】:

      您可以使用 LinearInterpolator

      代替 AccelerateInterpolator

      我知道为时已晚,但会帮助别人。

      【讨论】:

        猜你喜欢
        • 2011-05-04
        • 2013-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多