自定义圆和属性动画

自定义画圆


public class Custom extends View {
    public Custom(Context context) {
        super(context);
    }

    public Custom(Context context,  AttributeSet attrs) {
        super(context, attrs);
    }

    public Custom(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        canvas.drawCircle(50,50,50,paint);
    }
}

activity布局

	//自定义圆的控件
  <crq.bwei.com.qiu.Custom
        android:id="@+id/custom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        />

activity代码

public class MainActivity extends AppCompatActivity {

    private Custom custom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        custom = findViewById(R.id.custom);
        custom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                PropertyValuesHolder alpha1 = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);
                PropertyValuesHolder scaleX1 = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
                PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
                PropertyValuesHolder rotation1 = PropertyValuesHolder.ofFloat("rotation", 0.0f, 360f);
                PropertyValuesHolder translationX1 = PropertyValuesHolder.ofFloat("translationX",200f);
                PropertyValuesHolder translationY1 = PropertyValuesHolder.ofFloat("translationY",200f);
                PropertyValuesHolder translationX2 = PropertyValuesHolder.ofFloat("translationX",0f);
                PropertyValuesHolder translationY2 = PropertyValuesHolder.ofFloat("translationY",0f);

                //****************
          /*      PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f,0f, 1f);
                PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f,	0, 1f);
                PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f,	0, 1f);*/

                ObjectAnimator.ofPropertyValuesHolder(custom, translationY1).setDuration(3000).start();

            }
        });

        //3秒后跳转
        Timer timer=new Timer();
        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                Intent intent=new Intent(MainActivity.this,TwoActivity.class);
                startActivity(intent);
            }
        };
        timer.schedule(task,3000);


    }
}

'
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值