java代码实现的帧动画

1、效果图


2、帧动画的简要代码
   private ImageView bgAnimView;
   private AnimationDrawable mAnimationDrawable;


		//初始化
        mAnimationDrawable = new AnimationDrawable();
        bgAnimView = new ImageView(mContext);
        bgAnimView.setBackgroundDrawable(getAnimationDrawable(mAnimationDrawable));
        params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.topMargin = Util.Div(176 + 58);
        params.gravity = Gravity.CENTER_HORIZONTAL;
        addView(bgAnimView, params);
      
 
  private AnimationDrawable getAnimationDrawable(AnimationDrawable mAnimationDrawable) {
        int duration = 50;
        mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading1), duration);
        mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading2), duration);
        mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading3), duration);

        mAnimationDrawable.setOneShot(false);

        return mAnimationDrawable;
    }

    //动画开始
    public void animLoadingStart() {
        this.setVisibility(View.VISIBLE);
        if (mAnimationDrawable != null) {
            mAnimationDrawable.start();
        }


    }
    //动画结束
    public void animLoadingEnd() {
        if (mAnimationDrawable != null) {
            mAnimationDrawable.stop();
        }

		


3、扩展:

	
	//X轴平移
    public void animY(int y, int nextY, int duration) {
        LinearInterpolator ll = new LinearInterpolator(); //匀速
        ObjectAnimator animator = ObjectAnimator.ofFloat(yourView, "translationY", 0, 300);//300若为负值,就是向上平移
        animator.setDuration(duration);
        animator.setInterpolator(ll);
        animator.start();

    }

	//Y轴平移
    public void animX(int x, int nextX, int duration) {
        LinearInterpolator ll = new LinearInterpolator();
        ObjectAnimator animator = ObjectAnimator.ofFloat(yourView, "translationX", x, nextX);
        animator.setDuration(duration);
        animator.setInterpolator(ll);
        animator.start();
    }
	
	
	//纵向压缩0.5倍
	    LinearInterpolator ll = new LinearInterpolator();//匀速
        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1, 1, 0.5f);//默认从(0,0)
        scaleAnimation.setDuration(500);
        scaleAnimation.setInterpolator(ll);
        scaleAnimation.setFillAfter(true);
        chartView.startAnimation(scaleAnimation);
		
		
			
	//横向压缩0.5倍
	    LinearInterpolator ll = new LinearInterpolator();
        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.5f, 1, 1);//默认从(0,0)
        scaleAnimation.setDuration(500);
        scaleAnimation.setInterpolator(ll);
        scaleAnimation.setFillAfter(true);
        chartView.startAnimation(scaleAnimation);

点击打开素材下载地址


  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值