Tween动画xml
16lz
2021-01-26
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, 0, 0, null); }}alpha
<?xml version="1.0" encoding="utf-8"?><alphaxmlns: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"?><rotatexmlns: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"?><scalexmlns: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"?><translatexmlns:android="http://schemas.android.com/apk/res/android"android:fromXDelta="10"android:toXDelta="100"android:fromYDelta="10"android:toYDelta="100"android:duration="1000"></translate>
更多相关文章
- Android(安卓)shape使用笔记
- Android(安卓)Drawable之GradientDrawable
- Android(安卓)Animation解析
- Android(安卓)自定义Galley中图片未居中显示问题
- 【Android动画九章】-AlphaAnimation(渐变动画)
- Android(安卓)如何去除桌面上下边框暗度逐渐变暗的效果
- Android(安卓)安卓动画 补间动画 - 旋转动画
- Android(安卓)UI美化之Shape Drawable的使用
- Android沉浸式状态栏/状态栏设置背景图片/自定义渐变式状态栏