zoukankan      html  css  js  c++  java
  • android FrameByFrame Animations(一帧一帧地播放动画)的使用

    程序功能,点击按钮时,图片一张一张循环播放:

    直接来代码:

    AppMain.java

    [java] view plaincopy

    1. package lxy.litsoft; 
    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 AppMain extends Activity { 
    10. //声明对象
    11.     ImageView disPic; 
    12.     Button btDis; 
    13. public void onCreate(Bundle savedInstanceState) { 
    14. super.onCreate(savedInstanceState); 
    15.         setContentView(R.layout.main); 
    16. //实例化对象
    17.         disPic = (ImageView)findViewById(R.id.imageView01); 
    18.         btDis = (Button)findViewById(R.id.button01); 
    19. //绑定监听器
    20.         btDis.setOnClickListener(new ButtonListener()); 
    21.     } 
    22. //按钮的监听器实现
    23. class ButtonListener implements OnClickListener{ 
    24. public void onClick(View v) { 
    25. //动画播放
    26.             disPic.setBackgroundResource(R.drawable.anim); 
    27.             AnimationDrawable animationDrawable = (AnimationDrawable)disPic.getBackground(); 
    28.             animationDrawable.start(); 
    29.         } 
    30.     } 

    main.xml

    [html] view plaincopy

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:orientation="vertical"
    4. android:layout_width="fill_parent"
    5. android:layout_height="fill_parent" >
    6. <TextView
    7. android:layout_width="fill_parent"
    8. android:layout_height="wrap_content"
    9. android:text="@string/hello"/>
    10. <ImageView
    11. android:id="@+id/imageView01"
    12. android:layout_width="wrap_content"
    13. android:layout_height="wrap_content"></ImageView>
    14. <Button
    15. android:id="@+id/button01"
    16. android:layout_width="fill_parent"
    17. android:layout_height="wrap_content"
    18. android:text="Anim"></Button>
    19. </LinearLayout>

    res/drawable/anim.xml

    [html] view plaincopy

    1. <animation-list
    2. xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:oneshot="false">
    4. <item android:drawable="@drawable/p30"
    5. android:duration="300"/>
    6. <item android:drawable="@drawable/p31"
    7. android:duration="300"/>
    8. <item android:drawable="@drawable/p32"
    9. android:duration="300"/>
    10. <item android:drawable="@drawable/p33"
    11. android:duration="300"/>
    12. <item android:drawable="@drawable/p34"
    13. android:duration="300"/>
    14. <item android:drawable="@drawable/p35"
    15. android:duration="300"/>
    16. <item android:drawable="@drawable/p36"
    17. android:duration="300"/>
    18. <item android:drawable="@drawable/p37"
    19. android:duration="300"/>
    20. </animation-list>

    其中每一个item就是一帧的资源,android:drawable是图片资源,android:duration是每一帧的显示时间。

  • 相关阅读:
    svn的revert、checkout、clean up、setting
    jsonp跨域原理
    王亚伟北大演讲:一切通胀问题都是货币问题(全文)
    string <-> wstring
    点在多边形内 经典算法(转)
    不可不表的OSG智能指针之强指针与弱指针 《转载》
    一个shell脚本给客户使用服务器生成一个序列号
    Rsync(远程同步): linux中Rsync命令的实际示例
    一个 rsync同步文件脚本
    用UltraISO制作CentOS U盘安装盘
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/3118010.html
Copyright © 2011-2022 走看看