FAQ Database Discussion Community


How can I calculate where to start my line based on the stroke cap?

android,drawing,ondraw,stroke
I'm trying to draw a line, but I need to take the width of the stroke cap into account so I don't overflow the container. I have code that looks like this... private void initialize() { this.paint = new Paint(); this.paint.setColor(Color.BLACK); this.paint.setStyle(Paint.Style.STROKE); this.paint.setStrokeCap(Paint.Cap.ROUND); this.paint.setStrokeWidth(1); } public void setStrokeWidth(float strokeWidth) {...

Calling custom view from main activity.. Message in onDraw() is printed but custom view is not rendered

android,render,android-custom-view,ondraw
I have two classes - MainActivity.java and MainView.java. I'm trying to render a custom view (defined in MainView.java) when screen is touched from the main activity. My code is doing a funky thing. From the main page, when you touch the screen, it does NOT render the custom view I've...

Android Custom View: getting null references on every class members in the onDraw method

java,android,nullpointerexception,android-view,ondraw
I'm trying to create a android custom view and i'm facing a rather strange problem. Every data members I set in the constructor (String, Bitmap, ...) become null in the overriden onDraw method. Here's the code: public class SimulationView extends View { private static final String TAG = "SIMULATION_VIEW"; private...

Android, UI Element in custom View

android,android-view,ondraw
I'm getting used to creating custom views in android. One thing i wish todo is to include existing UI elements such as EditText, or Switch in my custom view. I have previously developed with Cocoa (iOS), and was able to instantiate native elements within my custom view. At onDraw(Canvas canvas)...

Why is my rectangle not updating in my canvas method?(android java)

java,android,canvas,ondraw
So I made a painting class which has got an ontouchevent method where i set the xpos of my rectangle to the xpos of the touch event but the rectangle isnt moving! how can I correct that? rectangle class: public class myRectangle{ public int xpos; public int ypos; public int...

Android - calculate arc angle

android,math,canvas,android-canvas,ondraw
I have an arc and i wish to draw scale marks at 0, 45, 90, 135, 180 degrees, can anyone help me with the math needed to achive the x,y of points 5 and 30 on this sketch?: here is my code for drawing the 1 scale mark. private void...