通过XML定义Tween(补间动画)指令完成动画

/**
 * Created by zhu on 2018/6/26.
 */

public class BicycleView_New extends View {

    private  Context context;
    private Animation mAnimationAlpha = null;

    private Animation mAnimationScale = null;

    private Animation mAnimationTranslate = null;

    private Animation mAnimationRotate = null;

    private AnimationSet as = null;

    Bitmap mBicycle = null;


    public BicycleView_New(Context context) {
        super(context);
        this.context = context;
        mBicycle = ((BitmapDrawable) getResources().getDrawable(
                R.drawable.qq
        )).getBitmap();
        //
//        mAnimationAlpha = new AlphaAnimation(
//                0.1f, 1.0f
//        );

        mAnimationAlpha = AnimationUtils.loadAnimation(
                context,R.anim.alpha_animation
        );
        mAnimationAlpha.setDuration(1000 * 4);





        mAnimationScale = AnimationUtils.loadAnimation(
                context,R.anim.scale_animation
        );
        mAnimationScale.setDuration(1000 * 4);

       mAnimationTranslate = AnimationUtils.loadAnimation(
                context,R.anim.translate_animation
        );

        mAnimationTranslate.setDuration(1000 * 6);

        mAnimationRotate = AnimationUtils.loadAnimation(
                context,R.anim.rotate_animation
        );

        mAnimationRotate.setDuration(1000 * 4);

//        as = new AnimationSet(true);
//        as.addAnimation(mAnimationAlpha);
//        as.addAnimation(mAnimationScale);
//        as.addAnimation(mAnimationTranslate);
//        as.addAnimation(mAnimationRotate);
//        as.setDuration(1000 * 4);

        as = (AnimationSet) AnimationUtils.loadAnimation(
                context,R.anim.com
        );



    }

    public BicycleView_New(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BicycleView_New(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(mBicycle, 0, 0, null);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {

        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_UP:
                startAnimation(mAnimationScale);
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                startAnimation(mAnimationTranslate);
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                startAnimation(mAnimationAlpha);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                startAnimation(mAnimationRotate);
                break;
            case KeyEvent.KEYCODE_DPAD_CENTER:
                startAnimation(as);
                break;
        }

        return true;
    }
}
 

xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="4000"
        android:fromAlpha="0.1"
        android:toAlpha="1.0"></alpha>
    <rotate
        android:duration="4000"
        android:fromDegrees="0"
        android:pivotX="30%"
        android:pivotY="30%"
        android:toDegrees="+360"></rotate>
    <scale
        android:duration="6000"
        android:fillAfter="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:pivotX="70%"
        android:pivotY="70%"
        android:toXScale="1.0"
        android:toYScale="1.0"></scale>
    <translate
        android:duration="6000"
        android:fromXDelta="5"
        android:fromYDelta="4"
        android:toXDelta="200"
        android:toYDelta="150"></translate>
</set>


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值