AlphaAnimation基础

前段时间,去一家很牛的公司面试了,人家问了很多新的技术,
      我都没怎么使用过或者听说过,最后结果可想而知。于是,
      我后面打算把自己所接触的领域扎扎实实的深入了解下去,
      从基础入手,当然中间也穿插进阶的东西,扎扎实实的研究。。。。。
AlphaAnimation
public class AlphaAnimation 
extends Animation 

java.lang.Objectandroid.view.animation.Animationandroid.view.animation.AlphaAnimation

google解释:

An animation that controls the alpha level of an object. Useful for fading things in and out. This animation ends up changing the alpha property of a Transformation.

大意是这个动画是通过修改alpha参数值,来达到淡入淡出的效果。它的一个构造函数为:

    /**
     * Constructor to use when building an AlphaAnimation from code
     * 
     * @param fromAlpha Starting alpha value for the animation, where 1.0 means
     *        fully opaque and 0.0 means fully transparent.
     * @param toAlpha Ending alpha value for the animation.
     */
    public AlphaAnimation(float fromAlpha, float toAlpha) {
        mFromAlpha = fromAlpha;
        mToAlpha = toAlpha;
    }

fromAlpha float: Starting alpha value for the animation, where 1.0 means fully opaque and 0.0 means fully transparent.
(动画开始alpha值,其中1.0表示完全不透明和0.0表示完全透明。)
toAlpha float: Ending alpha value for the animation.
(为动画结束时的alpha值)
例如:
AlphaAnimation(0.01f, 1.0f); 从0.01f到1.0f渐变。

我们继续研究的是该动画的监听方法

alphaAnimation.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation arg0) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onAnimationRepeat(Animation arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation arg0) {
                // TODO Auto-generated method stub
            }
        });

看方法名大概就猜得出大概什么意思了,但是我发现onAnimationRepeat这个
方法让我有点疑惑,Repeat中文解释为重复的意思,动画重复播放?于是我们捯饬捯饬一番,读者自行理会……
最终代码:

/**
 * @author spf
 * 
 * */
public class MainActivity extends Activity {
    TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.01f, 1.0f);
        alphaAnimation.setDuration(5000);
        alphaAnimation.setRepeatCount(4);
        tv=(TextView) findViewById(R.id.tv);
        tv.startAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub
            Log.i("MainActivity", "动画star");
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub
            Log.i("MainActivity", "动画Repeat");
        }

        @Override
        public void onAnimationEnd(Animation arg0) {
            // TODO Auto-generated method stub
            Log.i("MainActivity", "动画end");
        }
    });
    }
}

实际运行Log结果:
这里写图片描述

Log一共是6个动画相关的结果,手机实际运行结果一共有5个动画,其中动画结束(onAnimationEnd执行时)不播放动画。

void    setRepeatCount(int repeatCount)
将动画设置应重复多少次。

大意:getRepeatCount()定义动画应该重复多少次。

我想到此,关于AlphaAnimation基础就算是了解完了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值