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;

    }

    }

  • 相关阅读:
    HDU 5492 Find a path
    codeforce gym 100548H The Problem to Make You Happy
    Topcoder SRM 144 Lottery
    codeforce 165E Compatible Numbers
    codeforce gym 100307H Hack Protection
    区间DP总结
    UESTC 1321 柱爷的恋爱 (区间DP)
    HDU 4283 You Are the One (区间DP)
    HDU 2476 String painter (区间DP)
    UESTC 426 Food Delivery (区间DP)
  • 原文地址:https://www.cnblogs.com/danmao/p/3808649.html
Copyright © 2011-2022 走看看