zoukankan      html  css  js  c++  java
  • frame动画

    package com.example.examples_05_17;

     

    import android.R.drawable;

    import android.R.integer;

    import android.content.Context;

    import android.graphics.Canvas;

    import android.graphics.drawable.AnimationDrawable;

    import android.graphics.drawable.Drawable;

    import android.view.View;

    import android.widget.Toast;

     

    public class GameView extends View {

     

    //定义AnimationDrawable

    public AnimationDrawable frameAnimation=null;

     

    Context mContext;

     

    //定义一个Drawable对象

    Drawable mBitAnimation=null;

    public GameView(Context context) {

    super(context);

    // TODO Auto-generated constructor stub

    mContext=context;

    //创建实例

    frameAnimation=new AnimationDrawable();

     

    //装载资源

    /*

     * 这里用一个for循环装载所有名字类型的资源

     * "a1......a15.png"的图片

     *  这个方法的用处很大

     */

    for (int i = 1; i <= 15; i++) {

    int id=getResources().getIdentifier("a"+i, "drawable", mContext.getPackageName());

    //Toast.makeText(mContext, id+"", Toast.LENGTH_SHORT).show();

    mBitAnimation=getResources().getDrawable(id);

    //为动画添加一帧

    //mBitAnimation该帧的图片

    //参数500是该帧的显示时间,以毫秒算

    frameAnimation.addFrame(mBitAnimation, 500);

    }

    //这里播放是否循环,true为循环,false为不循环

    frameAnimation.setOneShot(true);

    //设置本类将要显示这个动画

    this.setBackgroundDrawable(frameAnimation);

    }

    }

     

     

    package com.example.examples_05_17;

     

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.KeyEvent;

     

    public class MainActivity extends Activity {

     

    GameView gameView=null;

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            gameView=new GameView(this);

            setContentView(gameView);

        }

        public boolean onKeyDown(int keyCode,KeyEvent event) {

    if(keyCode==KeyEvent.KEYCODE_DPAD_UP)

    {

    //开启播放

    gameView.frameAnimation.start();

    }

    return true;

    }

    }

  • 相关阅读:
    C#扩展方法学习
    如何用PS快速做出3D按钮效果的图片
    比较C#中几种常见的复制字节数组方法的效率[转]
    GUID的学习
    委托与事件的区别
    利用Marshal.AllocHGlobal申请非托管内存,unsafe代码
    JAVASE(十三) 异常处理
    JAVASE(十二) Java常用类: 包装类、String类、StringBuffer类、时间日期API、其他类
    JAVASE(十一) 高级类特性: abstract 、模板模式、interface、内部类、枚举、注解
    面试题: SpringBoot 的自启动原理
  • 原文地址:https://www.cnblogs.com/danmao/p/3808649.html
Copyright © 2011-2022 走看看