微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tween动画xml

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

/**
 * @version 2012-8-16 下午02:25:19
 **/
public class myGameView extends View {
    // 渐变透明
    private Animation mAnimationAlpha = null;
    // 渐变尺寸伸缩
    private Animation mAnimationScale = null;
    // 渐变位置移动
    private Animation mAnimationTranslate = null;
    // 渐变画面旋转
    private Animation mAnimationRotate = null;

    Bitmap bitmap = null;
    Context context = null;

    public myGameView(Context context) {
        super(context);
        bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.icon))
                .getBitmap();
        // 设置焦点 就可以使用onKeyDown
        setFocusable(true);
        this.context = context;
    }

    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event) {
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_UP:
                mAnimationAlpha = AnimationUtils.loadAnimation(context,R.anim.alpha);
                startAnimation(mAnimationAlpha);
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:

                mAnimationScale = AnimationUtils.loadAnimation(context,R.anim.scale);
                startAnimation(mAnimationScale);
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                mAnimationTranslate = AnimationUtils.loadAnimation(context,R.anim.translate);
                startAnimation(mAnimationTranslate);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:

                mAnimationRotate = AnimationUtils.loadAnimation(context,R.anim.rotate);
                startAnimation(mAnimationRotate);
                break;
        }
        return super.onKeyDown(keyCode,event);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // Todo Auto-generated method stub
        super.onDraw(canvas);
        canvas.drawBitmap(bitmap,null);
    }
}
alpha
<?xml version="1.0" encoding="utf-8"?>
<alpha
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:fromAlpha="0.1"
	android:toAlpha="1.0"
	android:duration="2000">
</alpha>
rotate
<?xml version="1.0" encoding="utf-8"?>
<rotate
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:interpolator="@android:anim/accelerate_decelerate_interpolator"
	android:fromdegrees="0"
	android:todegrees="360"
	android:pivotX="0.5"
	android:pivotY="0.5"
	android:duration="1000">
</rotate>
scale
<?xml version="1.0" encoding="utf-8"?>
<scale
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:interpolator="@android:anim/accelerate_decelerate_interpolator"
	android:fromXScale="0.0"
	android:toXScale="1.0"
	android:fromYScale="0.0"
	android:toYScale="1.0"
	android:pivotX="50%"
	android:pivotY="50%"
	android:fillAfter="false"
	android:duration="500">
</scale>
translate
<?xml version="1.0" encoding="utf-8"?>
<translate
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:fromXDelta="10"
	android:toXDelta="100"
	android:fromYDelta="10"
	android:toYDelta="100"
	android:duration="1000">
</translate>

原文地址:https://www.jb51.cc/xml/296549.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。