在Android视图中绘制一个虚线圆圈

时间:2010-12-10 06:40:32

标签: android

我需要在视图中显示虚线圆圈。

1 个答案:

答案 0 :(得分:15)

试试这个解决方案:

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();
            }
        }
}