安卓(Android) 怎么用动画(Animation)显示图像(Image)

2019年10月16日23:21:06安卓(Android) 怎么用动画(Animation)显示图像(Image)已关闭评论 199 948字阅读3分9秒

1.简介

安卓(Android) 怎么用动画(Animation)显示图像(Image)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;

public class Main {
    private static AnimationSet showAction;
    private static AnimationSet hideAction;

    public static void showImage(View View, AnimationListener listener) {
        if (showAction == null) {
            initAnimation();
        }
        if (View.getVisibility() != View.VISIBLE) {
            View.setVisibility(View.VISIBLE);
            showAction.setAnimationListener(listener);
            View.startAnimation(showAction);
        }
    }

    private static void initAnimation() {
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(500);
        showAction = new AnimationSet(false);
        showAction.addAnimation(animation);

        animation = new AlphaAnimation(1.0f, 0.2f);
        animation.setDuration(2000);
        hideAction = new AnimationSet(false);
        hideAction.addAnimation(animation);
    }
}

 
继续阅读
编程十万个怎么办