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

简单属性动画

程序员文章站 2022-05-03 10:37:15
...
继承我view 实现三个方法 在进行绘制
 @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint=new Paint();
        paint.setStrokeWidth(5);
        paint.setColor(Color.GREEN);
        paint.setStyle(Paint.Style.FILL);

        canvas.drawCircle(60,60,60,paint);
    }
导入布局
  <com.example.myapplication.Viewcar.Crile
        android:layout_marginLeft="100dp"
        android:layout_marginTop="100dp"
        android:id="@+id/yuan"
        android:layout_width="199dp"
        android:layout_height="199dp" />
设置点击事件进行操作
 yuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(), "转起来", Toast.LENGTH_SHORT).show();
                //平移
                ObjectAnimator translationY=ObjectAnimator.ofFloat(yuan,"translationX",yuan.getTranslationY(),200,200);
                 //赞转
                ObjectAnimator rotation=ObjectAnimator.ofFloat(yuan,"rotation",0,360);
                 //透明度
                ObjectAnimator alpha=ObjectAnimator.ofFloat(yuan,"alpha",0,1,0,1);
                 //组合动画
                AnimatorSet animatorSet = new AnimatorSet();
                //播放顺序
                animatorSet.play(translationY).with(rotation).before(alpha);//一起
                //时间
                animatorSet.setDuration(5000);
                //开始
                animatorSet.start();

            }
        });