animations 动画图片的播放

Q群: 241359063 更精彩,欢迎共同走向创业学习之旅。
原创:kylin_zeng  http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。

1、在res/drawable-ldpi 目录下面建立anim_nv.xml文件,以及放入nv1.png, nv2.png, nv3.png, nv4.png

2、anim_nv.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:oneshot="false">
  4.     <item android:drawable="@drawable/nv1" android:duration="500" />
  5.     <item android:drawable="@drawable/nv2" android:duration="500" />
  6.     <item android:drawable="@drawable/nv3" android:duration="500" />
  7.     <item android:drawable="@drawable/nv4" android:duration="500" />
  8. </animation-list>
3、调用:

点击(此处)折叠或打开

  1. package mars.animations05;

  2. import android.app.Activity;
  3. import android.graphics.drawable.AnimationDrawable;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.ImageView;

  9. public class MainActivity extends Activity {
  10.     private Button button = null;
  11.     private ImageView imageView = null;
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.main);
  16.         imageView = (ImageView)findViewById(R.id.imageViewId);
  17.         button = (Button)findViewById(R.id.buttonId);
  18.         button.setOnClickListener(new ButtonListener());
  19.     }
  20.     
  21.     private class ButtonListener implements OnClickListener{

  22.         @Override
  23.         public void onClick(View v) {
  24.             imageView.setBackgroundResource(R.drawable.anim_nv);
  25.             AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
  26.             animationDrawable.start();
  27.         }
  28.         
  29.     }
  30. }

然后,这四种图片就可以一直循环的播放了。

15_animations05.rar
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(149) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值