加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Tween动画xml

发布时间:2020-12-16 06:15:56 所属栏目:百科 来源:网络整理
导读: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;impo
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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读