欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java实现帧动画的实例代码

程序员文章站 2024-02-11 08:27:22
本文讲述了java实现帧动画的实例代码。分享给大家供大家参考,具体如下: 1、效果图 2、帧动画的简要代码 private imageview bga...

本文讲述了java实现帧动画的实例代码。分享给大家供大家参考,具体如下:

1、效果图

Java实现帧动画的实例代码

2、帧动画的简要代码

private imageview bganimview; 
 private animationdrawable manimationdrawable; 
//初始化 
 manimationdrawable = new animationdrawable(); 
 bganimview = new imageview(mcontext); 
 bganimview.setbackgrounddrawable(getanimationdrawable(manimationdrawable)); 
 params = new framelayout.layoutparams(viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content); 
 params.topmargin = util.div(176 + 58); 
 params.gravity = gravity.center_horizontal; 
 addview(bganimview, params); 
private animationdrawable getanimationdrawable(animationdrawable manimationdrawable) { 
 int duration = 50; 
 manimationdrawable.addframe(mcontext.getresources().getdrawable(r.drawable.loading1), duration); 
 manimationdrawable.addframe(mcontext.getresources().getdrawable(r.drawable.loading2), duration); 
 manimationdrawable.addframe(mcontext.getresources().getdrawable(r.drawable.loading3), duration); 
 manimationdrawable.setoneshot(false); 
 return manimationdrawable; 
 } 
 //动画开始 
 public void animloadingstart() { 
 this.setvisibility(view.visible); 
 if (manimationdrawable != null) { 
 manimationdrawable.start(); 
 } 
 } 
 //动画结束 
 public void animloadingend() { 
 if (manimationdrawable != null) { 
 manimationdrawable.stop(); 
 } 

3、扩展:

//x轴平移 
 public void animy(int y, int nexty, int duration) { 
 linearinterpolator ll = new linearinterpolator(); //匀速 
 objectanimator animator = objectanimator.offloat(yourview, "translationy", 0, 300);//300若为负值,就是向上平移 
 animator.setduration(duration); 
 animator.setinterpolator(ll); 
 animator.start(); 
 } 
//y轴平移 
 public void animx(int x, int nextx, int duration) { 
 linearinterpolator ll = new linearinterpolator(); 
 objectanimator animator = objectanimator.offloat(yourview, "translationx", x, nextx); 
 animator.setduration(duration); 
 animator.setinterpolator(ll); 
 animator.start(); 
 } 
//纵向压缩0.5倍 
 linearinterpolator ll = new linearinterpolator();//匀速 
 scaleanimation scaleanimation = new scaleanimation(1, 1, 1, 0.5f);//默认从(0,0) 
 scaleanimation.setduration(500); 
 scaleanimation.setinterpolator(ll); 
 scaleanimation.setfillafter(true); 
 chartview.startanimation(scaleanimation); 
//横向压缩0.5倍 
 linearinterpolator ll = new linearinterpolator(); 
 scaleanimation scaleanimation = new scaleanimation(1, 0.5f, 1, 1);//默认从(0,0) 
 scaleanimation.setduration(500); 
 scaleanimation.setinterpolator(ll); 
 scaleanimation.setfillafter(true); 
 chartview.startanimation(scaleanimation); 

点击打开素材下载地址

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。