欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义圆+动画效果_ObjectAnimator_AnimatorSet

程序员文章站 2022-05-03 09:07:04
...

自定义view_圆

public ZdyXq(Context context) {
        super(context);
    }

    public ZdyXq(Context context, AttributeSet attrs) {
        super(context, attrs);

    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint pa1 = new Paint();
        pa1.setColor(Color.BLUE);
        pa1.setAntiAlias(true);
        canvas.drawCircle(100,100,100,pa1);
     }

布局使用

   <com.zzc.admin.day16_dh.ZdyXq
        android:id="@+id/yuan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Activity_动画效果

       zd = (ZdyXq)findViewById(R.id.zd);

        //平移
        ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(zd, "translationY", 0, 1400f);
        ObjectAnimator objectAnimator1= ObjectAnimator.ofFloat(zd, "translationX",0,900f);

        AnimatorSet animset = new AnimatorSet();
        animset.play(objectAnimator).with(objectAnimator1);
        animset.setDuration(8000);
        animset.start();

        animset.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {

                Intent intent = new Intent(MainActivity.this,DengActivity.class);
                startActivity(intent);
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });