Android custom view with canvas
NickName:user3600801 Ask DateTime:2016-02-25T17:03:21

Android custom view with canvas

I would like to create a custom bullet points in android using canvas.

Following is my code.

protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            int x = getWidth();
            int y = getHeight();
            int radius;
            radius = 100;
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.WHITE);
            canvas.drawPaint(paint);
            // Use Color.parseColor to define HTML colors
            paint.setColor(Color.parseColor("#CD5C5C"));
            canvas.drawCircle(x / 2, y / 2, radius, paint);
        }

But it doesn't produce the view that Im trying to get. Im enclosing a image as a reference. I wish to get such view.

enter image description here

Copyright Notice:Content Author:「user3600801」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35622639/android-custom-view-with-canvas

More about “Android custom view with canvas” related questions

Android custom View dimensions and canvas coordinates

I have custom View that should paint a bitmap. I've created a simple line(bmp 1x50 px) to check where will be drawn exactly. In my onDraw(Canvas c) I'm using this line of code: canvas.drawBitmap(b...

Show Detail

Android custom view with canvas

I would like to create a custom bullet points in android using canvas. Following is my code. protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.

Show Detail

Unable to perform click on a custom view inflated on the top of android Canvas?

I have been trying to build a popup on canvas click, which further has buttons on it. I inflated the popup on the canvas, but when i try clicking on it the popup closes. This is how i am inflating...

Show Detail

Canvas does not draw in Custom View

I created a Custom View CircleView like this: public class CircleView extends LinearLayout { Paint paint1; public CircleView(Context context) { super(context); init(); ...

Show Detail

Can we use and draw view inside custom view using canvas on Android?

I would like to know if it possible to use and draw a view such as a TextView or Chronometer inside my custom View which uses the canvas to perform drawing. My goal is to reuse the Chonometer view ...

Show Detail

android custom view not inflating

I made a custom view that extends the View class: import android.content.Context; import android.graphics.Canvas; import android.view.View; public class DrawSurfaceView extends View { private

Show Detail

How does rtl work with custom view or canvas in Android

I just wanted to know, how does Android work with custom view canvas in RTL mode. As with this example, question link. It works great with english locale but when locale is changed to arabic, its ...

Show Detail

Canvas is not drawing in custom Android View

I have created my custom View in Android and trying to draw a circle in that but nothing is drawing but with no errors. Here is my code public class ColorOptionsView extends RelativeLayout { p...

Show Detail

padding custom view canvas

I newbie to android and I have a question(probably dummy question ...) I am creating a custom view by extending View element. I start to draw and notice that my drawings is clipped a little bit at...

Show Detail

Redrawing Canvas in Android custom View

I am trying to set up a canvas to redraw whenever the user clicks a button. Whenever I trigger the redraw via invalidate() the app freezes and crashes. I am very new to android development so I am

Show Detail