• android 2D动画实现


    不管,先上截图

    代码:只有一个activity

    MainActivity:代码很简单

    package com.animation.test;
    
    import zhuojin.lession15.animation.frame.R;
    import android.app.Activity;
    import android.graphics.drawable.AnimationDrawable;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    
        ImageView img1=null;
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            img1=(ImageView)findViewById(R.id.img1);
        }
        AnimationDrawable   anim=new AnimationDrawable();
        
        public  void startBtn(View v)
        {
          for(int i=0;i<8;i++)
          {
              anim.addFrame(this.getResources().getDrawable(R.drawable.walk1+i), 100);
          }
            anim.setOneShot(false);
            img1.setBackgroundDrawable(anim);
            if(anim.isRunning())
            {
                anim.stop();
            }else
            {
                anim.stop();
                anim.start();
            }
        }
    }

    代码结构

    在drawbale文件夹下有个walkgirl.xml的文件,这个文件,实际上描述了切换图片的一个帧率。其实2D动画的实现也就是多个图片的展示

    walkgirl.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/walk1" android:duration="50" />
        <item android:drawable="@drawable/walk2" android:duration="50" />
        <item android:drawable="@drawable/walk3" android:duration="50" />
        <item android:drawable="@drawable/walk4" android:duration="50" />
        <item android:drawable="@drawable/walk5" android:duration="50" />
        <item android:drawable="@drawable/walk6" android:duration="50" />
        <item android:drawable="@drawable/walk7" android:duration="50" />
        <item android:drawable="@drawable/walk8" android:duration="50" />
    </animation-list>

    无语了,这博客园怎么上传代码。。

  • 相关阅读:
    基于php5.5使用PHPMailer-5.2发送邮件
    centos安装memcached和PHP php-pecl-memcached.x86_64
    修改覆盖springboot默认日志策略logback
    Springboot打包支持第三方jar
    Intellij IDEA 快速添加maven依赖
    Mybatis Generator生成Example类方法解释
    MyBatis generator生成的Example文件用法
    Intellij IDEA 中怎么把这个黄色的填充色取消?
    MyBatis自动生成工具去掉注释的配置
    去掉Mybatis Generator生成的example
  • 原文地址:https://www.cnblogs.com/sy171822716/p/2647240.html
Copyright © 2020-2023  润新知