Draw a dotted circle in Android View [closed]

2020-04-03 03:15发布

I need to display a dotted circle within a view.

标签: android
1条回答
够拽才男人
2楼-- · 2020-04-03 03:59

Try this solution:

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(demoview);
        }

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

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);
                Paint p = new Paint();
                p.setColor(Color.RED);
                DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);

                p.setPathEffect(dashPath);
                p.setStyle(Style.STROKE);
                canvas.drawCircle(100, 100, 50, p);

                invalidate();
            }
        }
}
查看更多
登录 后发表回答