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