Home > Web Front-end > HTML Tutorial > Two ways to implement android animation animation effects_html/css_WEB-ITnose

Two ways to implement android animation animation effects_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:44:16
Original
1259 people have browsed it

Two ways to implement animation effect

Note: This example is AlphaAnimation effect. As for other effects, just change the object.

1. .java file code control to add and start animation

//添加动画效果		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);
Copy after login

2. .xml file code to load xml and start 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>
Copy after login

Code loading xml:


Attributes:

private Animation anim;	private AnimationListener animLis;
Copy after login
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);
Copy after login



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template