sek sek - 4 months ago 39
Java Question

How to draw a dotted circle in android sdk?

I am very new to Android sdk. I need to display a dotted circle with in the view. But My requirement is to display a dotted circle. But I don't have an idea how to do it?. Can you guys please let me know if any one know this ?

Thank you,
-Sek.

Answer

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