public class MyView extends View implements AnimationListener {    public static MyView mv;    private Paint paint;    private Bitmap bmp;    private int x = 50;    private Animation mAlphaAnimation;    private Animation mScaleAnimation;    private Animation mTranslateAnimation;    private Animation mRotateAnimation;    public MyView(Context context) {        super(context);        mv = this;        paint = new Paint();        paint.setColor(Color.WHITE);        paint.setAntiAlias(true);        bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);        this.setFocusable(true);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        //黑色背景        canvas.drawColor(Color.BLACK);        canvas.drawText("方向键↑ 渐变透明度动画效果", 80, this.getHeight() - 80, paint);        canvas.drawText("方向键↓ 渐变尺寸伸缩动画效果", 80, this.getHeight() - 60, paint);        canvas.drawText("方向键← 画面转换位置移动动画效果", 80, this.getHeight() - 40, paint);        canvas.drawText("方向键→ 画面转移旋转动画效果", 80, this.getHeight() - 20, paint);        //绘制位图icon        canvas.drawBitmap(bmp, this.getWidth() / 2 - bmp.getWidth() / 2, this.getHeight() / 2 - bmp.getHeight() / 2, paint);        x += 1;    }    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {// 渐变透明度动画效果            mAlphaAnimation = new AlphaAnimation(0.1f, 1.0f);            mAlphaAnimation.setAnimationListener(this);            mAlphaAnimation.setDuration(3000);            // //设置时间持续时间为3000 毫秒=3秒            this.startAnimation(mAlphaAnimation);        } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {// 渐变尺寸伸缩动画效果            mScaleAnimation = new ScaleAnimation(0.0f, 2.0f, 1.5f, 1.5f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.0f);            mScaleAnimation.setAnimationListener(this);            mScaleAnimation.setDuration(2000);            this.startAnimation(mScaleAnimation);        } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {// 画面转换位置移动动画效果            mTranslateAnimation = new TranslateAnimation(0, 100, 0, 100);            mTranslateAnimation.setAnimationListener(this);            mTranslateAnimation.setDuration(2000);            this.startAnimation(mTranslateAnimation);        } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {// 画面转移旋转动画效果            mRotateAnimation = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);            mRotateAnimation.setAnimationListener(this);            mRotateAnimation.setDuration(3000);            this.startAnimation(mRotateAnimation);        }        return super.onKeyDown(keyCode, event);    }    @Override    public void onAnimationStart(Animation animation) {        Log.e("", "AnimationStart!");    }    @Override    public void onAnimationEnd(Animation animation) {        Log.e("", "AnimationEnd!");    }    @Override    public void onAnimationRepeat(Animation animation) {        Log.e("", "AnimationRepeat!");    }}

更多相关文章

  1. toast的五种效果
  2. android Tween Animations(动画效果-代码实现)的使用
  3. Android(安卓)OpenGL ES和OpenGL一起学(二)------理解Viewport(视口
  4. Android中使用NavigationView实现抽屉侧滑效果中Menu菜单栏设置
  5. Android(安卓)左右滑动切换页面或Activity的效果实现
  6. VectorDrawable兼容笔记
  7. Android(安卓)自定义View实现动画形式加载环形图
  8. Android实现镜花水月的效果
  9. [Android(安卓)Studio]设置Button的圆角、点击效果、按钮颜色

随机推荐

  1. 在android 中调用其他的功能
  2. Android Studio 配置输出apk的名字
  3. android fragment 面试
  4. android通过图片名称获取资源识别码
  5. android中使用static、application、本地
  6. Android G711A编解码
  7. android银行卡操作步骤
  8. ANDROID音频系统散记之四:4.0音频系统HAL
  9. 常用adb命令
  10. Android - 详情页面【仿】淘宝App