自定义画圆
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);
}
}
'