zoukankan      html  css  js  c++  java
  • Android通过播放多张图片形成一个动画 分类: Android 2015-04-24 14:05 16人阅读 评论(0) 收藏

    Andriod里可以逐帧的播放图片,然后产生一种动态的效果.

    1.准备好几张连续的图片,在源程序res文件夹下建立anim文件夹,然后新建一个XML:

    <?xml version="1.0" encoding="utf-8"?>   
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"    
    android:oneshot="true">    
    <item android:drawable="@drawable/row01" android:duration="200" />    
    <item android:drawable="@drawable/row02" android:duration="200" />    
    <item android:drawable="@drawable/row03" android:duration="200" />   
    <item android:drawable="@drawable/row04" android:duration="200" /> 
    <item android:drawable="@drawable/row05" android:duration="200" /> 
    <item android:drawable="@drawable/row06" android:duration="200" />    
    <item android:drawable="@drawable/row07" android:duration="200" />   
    <item android:drawable="@drawable/row08" android:duration="200" />   
    </animation-list>  

    2.在窗体里面放置一个ImageView控件,并在代码中编写:
    iv_run_row =(ImageView)findViewById(R.id.run_row);//放置的ImageView控件
    //设置动画背景 
    iv_run_row.setBackgroundResource(R.anim.running_row);//其中R.anim.animation_list就是上一步准备的动画描述文件的资源名 
    //获得动画对象 
    run_row_animaition = (AnimationDrawable)iv_run_row.getBackground();

    3.编写方法,调用该方法即可实现动画播放。

    private void runRow() {

    //是否仅仅启动一次?
    run_row_animaition.setOneShot(false);  
    if(run_row_animaition.isRunning())//是否正在运行? 
    {   
    run_row_animaition.stop();//停止 
    }   
    run_row_animaition.start();//启动
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    [模板]KMP
    [BZOJ] 1833: [ZJOI2010]count 数字计数
    [BZOJ] 1563: [NOI2009]诗人小G
    [BZOJ] 2442: [Usaco2011 Open]修剪草坪
    [LOJ] #2360. 「NOIP2016」换教室
    9.18模拟赛
    [BZOJ] 2006: [NOI2010]超级钢琴
    [BZOJ] 1143: [CTSC2008]祭祀river
    [51Nod] 1218 最长递增子序列 V2
    [BZOJ] 3307: 雨天的尾巴
  • 原文地址:https://www.cnblogs.com/xieping/p/4666313.html
Copyright © 2011-2022 走看看