以下只列出主要代码:
[java]
private ImageView scanLight;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanLight = (ImageView)findViewById(R.id.img);
Button translateStart = (Button)findViewById(R.id.translateStart);
Button translateEnd = (Button)findViewById(R.id.translateEnd);
Button scaleStart = (Button)findViewById(R.id.scaleStart);
Button scaleEnd = (Button)findViewById(R.id.scaleEnd);
Button alphaStart = (Button)findViewById(R.id.alphaStart);
Button alphaEnd = (Button)findViewById(R.id.alphaEnd);
Button rotateStart = (Button)findViewById(R.id.rotateStart);
Button rotateEnd = (Button)findViewById(R.id.rotateEnd);
translateStart.setOnClickListener(listener);
translateEnd.setOnClickListener(listener);
scaleStart.setOnClickListener(listener);
scaleEnd.setOnClickListener(listener);
alphaStart.setOnClickListener(listener);
alphaEnd.setOnClickListener(listener);
rotateStart.setOnClickListener(listener);
rotateEnd.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
//平移 setFillAfter(true) 控制执行动画后定在当前状态
case R.id.translateStart:
Animation translateIn = new TranslateAnimation(0, 100, 0, 0);
translateIn.setDuration(500);
translateIn.setFillAfter(true);
scanLight.startAnimation(translateIn);
break;
case R.id.translateEnd:
Animation translateOut = new TranslateAnimation(100, 0, 0, 0);
translateOut.setDuration(500);
translateOut.setFillAfter(true);
scanLight.startAnimation(translateOut);
break;
//缩放 后四个参数控制沿自身中心点缩放
case R.id.scaleStart:
Animation sIn = new ScaleAnimation(1f, 2f, 1f, 2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
sIn.setDuration(500);
sIn.setFillAfter(true);
scanLight.startAnimation(sIn);
break;
case R.id.scaleEnd:
Animation sOut = new ScaleAnimation(2f, 1f, 2f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
sOut.setDuration(500);
sOut.setFillAfter(true);
scanLight.startAnimation(sOut);
break;
//透明度
case R.id.alphaStart:
Animation aIn = new AlphaAnimation(1f, 0f);
aIn.setDuration(500);
aIn.setFillAfter(true);
scanLight.startAnimation(aIn);
break;
case R.id.alphaEnd:
Animation aOut = new AlphaAnimation(0f, 1f);
aOut.setDuration(500);
aOut.setFillAfter(true);
scanLight.startAnimation(aOut);
break;
//旋转 后四个参数控制沿自身中心点旋转
case R.id.rotateStart:
Animation rIn = new RotateAnimation(0f, +360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rIn.setDuration(500);
rIn.setFillAfter(true);
scanLight.startAnimation(rIn);
break;
case R.id.rotateEnd:
Animation rOut = new RotateAnimation(+360f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rOut.setDuration(500);
rOut.setFillAfter(true);
scanLight.startAnimation(rOut);
break;
default:
break;
}
}
};
private ImageView scanLight;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanLight = (ImageView)findViewById(R.id.img);
Button translateStart = (Button)findViewById(R.id.translateStart);
Button translateEnd = (Button)findViewById(R.id.translateEnd);
Button scaleStart = (Button)findViewById(R.id.scaleStart);
Button scaleEnd = (Button)findViewById(R.id.scaleEnd);
Button alphaStart = (Button)findViewById(R.id.alphaStart);
Button alphaEnd = (Button)findViewById(R.id.alphaEnd);
Button rotateStart = (Button)findViewById(R.id.rotateStart);
Button rotateEnd = (Button)findViewById(R.id.rotateEnd);
translateStart.setOnClickListener(listener);
translateEnd.setOnClickListener(listener);
scaleStart.setOnClickListener(listener);
scaleEnd.setOnClickListener(listener);
alphaStart.setOnClickListener(listener);
alphaEnd.setOnClickListener(listener);
rotateStart.setOnClickListener(listener);
rotateEnd.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
//平移 setFillAfter(true) 控制执行动画后定在当前状态
case R.id.translateStart:
Animation translateIn = new TranslateAnimation(0, 100, 0, 0);
translateIn.setDuration(500);
translateIn.setFillAfter(true);
scanLight.startAnimation(translateIn);
break;
case R.id.translateEnd:
Animation translateOut = new TranslateAnimation(100, 0, 0, 0);
translateOut.setDuration(500);
translateOut.setFillAfter(true);
scanLight.startAnimation(translateOut);
break;
//缩放 后四个参数控制沿自身中心点缩放
case R.id.scaleStart:
Animation sIn = new ScaleAnimation(1f, 2f, 1f, 2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
sIn.setDuration(500);
sIn.setFillAfter(true);
scanLight.startAnimation(sIn);
break;
case R.id.scaleEnd:
Animation sOut = new ScaleAnimation(2f, 1f, 2f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
sOut.setDuration(500);
sOut.setFillAfter(true);
scanLight.startAnimation(sOut);
break;
//透明度
case R.id.alphaStart:
Animation aIn = new AlphaAnimation(1f, 0f);
aIn.setDuration(500);
aIn.setFillAfter(true);
scanLight.startAnimation(aIn);
break;
case R.id.alphaEnd:
Animation aOut = new AlphaAnimation(0f, 1f);
aOut.setDuration(500);
aOut.setFillAfter(true);
scanLight.startAnimation(aOut);
break;
//旋转 后四个参数控制沿自身中心点旋转
case R.id.rotateStart:
Animation rIn = new RotateAnimation(0f, +360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rIn.setDuration(500);
rIn.setFillAfter(true);
scanLight.startAnimation(rIn);
break;
case R.id.rotateEnd:
Animation rOut = new RotateAnimation(+360f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rOut.setDuration(500);
rOut.setFillAfter(true);
scanLight.startAnimation(rOut);
break;
default:
break;
}
}
};
分享到:
相关推荐
下面小编就为大家带来一篇原生js实现jquery函数animate()动画效果的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Mapboxgl实现点animate动画效果
fullpage.js结合animate.css实现滚屏动画,每段代码都加有详细注释 文章地址:https://blog.csdn.net/cplvfx/article/details/80649574
实现效果: 基于animate.css和原生JS实现的鼠标滚动动画效果,挺不错的CSS3动画效果,基于CSS动画插件 animate.css实现,animate.css拥有众多的动画特效而且是开源的,大家到官网看看吧。
运用基本的属性设置,封装animate函数,实现li及其子元素在变换位置的时候有很好衔接的动画效果~~
animate动画特效重复调用animate动画特效重复调用animate动画特效重复调用
animate css最新4.1.1文件打包下载 制作前端动画效果,GitHub搬运方便下载
基于animate.css和原生JS实现的鼠标滚动动画效果,挺不错的CSS3动画效果,基于CSS动画插件 animate.css实现,animate.css拥有众多的动画特效而且是开源的,大家到官网看看吧。
多媒体应用基础所要求的 animate动画 绩点还不错 4.6 因为多个文件,所以就压缩了,上传的是rar文件。 下载后用win.rar解压了就好。 包括: 平时作业 期末作业,也就是animate动画源程序 《多媒体应用基础》(公选)...
利用animate制作互动动画案例,添加动作代码,可以通过鼠标切换帧
AnimateCC二维动画设计与制作-课程标准.pdf
Animate.css拥有多款文字特效的css3动画库效果源码,是一段拥有数十款文字特效的css3动画库代码,它预设了抖动(shake)、闪烁(flash)、弹跳(bounce)、翻转(flip)、旋转(rotateIn/rotateOut)、淡入淡出...
Animate.css是某位大牛写好的动画效果集合,需要的时候可以直接下载导入到项目中,在需要的元素上添加相关的类即可使用相对应的动画效果。
非常有用的web html5动画特效库Animate.css库,供大家下载使用。附有演示例子。
animate动画特效animate动画特效html5 css
Animate.css内置了很多典型的css3动画,兼容性好使用方便。 演示地址:http://www.jq22.com/jquery-info819
动画的前端实现,主要使用了animate
通过jQuery的animate方法实现的,广告联动动画效果,很简单
jquery实例超炫animate动画效果 demo是原版,效果还是相当炫丽 后面自制了两个
animate.css动画属性制作css3动画效果