《mainactivity布局 》
<com.bawei.mylianxitow.CricleView
android:id="@+id/cricle"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content” />
《CricleView 自定义view》
public class CricleView extends View {
private Paint mPaint;
public CricleView(Context context) {
super(context);
init(context);
}
public CricleView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
mPaint = new Paint();//画笔
mPaint.setColor(Color.RED);//颜色
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);//粗细
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(50, 50, 50, mPaint);
}
//传递颜色,改变颜色
public void setColor(int color){
mPaint.setColor(color);
invalidate();//刷新
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
}
《MainActivity 》
public class MainActivity extends AppCompatActivity {
private CricleView cricle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cricle = (CricleView) findViewById(R.id.cricle);
int width = getWindowManager().getDefaultDisplay().getWidth();//宽
int height = getWindowManager().getDefaultDisplay().getHeight();//高
ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(cricle, "translationX", 0, width - 100);
ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(cricle, "translationY", 0, height - 100);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(5000);
animatorSet.play(objectAnimatorX).with(objectAnimatorY);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
//跳转登录页面
startActivity(new Intent(MainActivity.this, TowActivity.class));
finish();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
cricle.setColor(Color.BLUE);
}
}, 500);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
cricle.setColor(Color.YELLOW);
}
}, 1000);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
cricle.setColor(Color.GREEN);
}
}, 1500);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
cricle.setColor(Color.WHITE);
}
}, 2000);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}
---------------------
【转载,仅作分享,侵删】
作者:偏执青年
原文:https://blog.csdn.net/weixin_44666694/article/details/88781996
版权声明:本文为博主原创文章,转载请附上博文链接!
|
|