Home >Web Front-end >HTML Tutorial >Two ways to implement android animation animation effects_html/css_WEB-ITnose
Two ways to implement animation effect
Note: This example is AlphaAnimation effect. As for other effects, just change the object.
//添加动画效果 AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f); //设置次效果的持续时间 animation.setDuration(2000); //设置动画的监听事件 animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { //动画开始监听事件 //do something... } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //动画结束监听事件 //do something... } }); //开始动画 view.startAnimation(animation);
alpha_out.xml Fade out effect
<?xml version="1.0" encoding="utf-8"?><!-- android:duration="@android:integer/config_mediumAnimTime" --><set xmlns:android="http://schemas.android.com/apk/res/android" ><alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="500"/> <!-- 透明度控制动画效果 alpha 浮点型值: fromAlpha 属性为动画起始时透明度 toAlpha 属性为动画结束时透明度 说明: 0.0表示完全透明 1.0表示完全不透明 以上值取0.0-1.0之间的float数据类型的数字 长整型值: duration 属性为动画持续时间 说明: 时间以毫秒为单位--></set>
Attributes:
private Animation anim; private AnimationListener animLis;Loading:
//初始化动画监听事件AnimationListener animLis = new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { //动画开始监听事件 //do something... } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { //动画结束监听事件 //do something... tv.setVisibility(View.GONE); } }; //加载xml anim = AnimationUtils.loadAnimation(this, R.anim.alpha_out); //设置监听事件 anim.setAnimationListener(animLis); //开始动画 tv.startAnimation(anim);