Questions tagged [ondraw]

onDraw is an event that is used in multiple languages/frameworks to notify the application that something needs to be (re)drawn.

onDraw is an event that is used in multiple languages/frameworks to notify the application that something needs to be (re)drawn.

The exact implementation and usage is depending on the framework implementation

Examples are:

662 questions
52
votes
1 answer

Custom Widget using LinearLayout not getting onDraw()

I'm creating a custom widget by extending LinearLayout: public class MyWidget extends LinearLayout { private static Paint PAINT = new Paint(Paint.ANTI_ALIAS_FLAG); static { PAINT.setColor(Color.RED); } public…
Steve Pomeroy
  • 10,071
  • 6
  • 34
  • 37
51
votes
7 answers

How to draw Arc between two points on the Canvas?

I have two points in the canvas, now I'm able to draw a line between those points like this below image by using This code canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint); I want to draw the arc between two points like below image. How can I draw…
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
47
votes
15 answers

Trying to get the display size of an image in an ImageView

I'm trying to get the real size of an image displayed in an image view. Actually my image is larger than the screen and the imageview is resizing the image to diplay it. I'm looking for this new size. I've tried to override the onDraw method of the…
Guillaume Ménant
  • 481
  • 1
  • 5
  • 3
38
votes
6 answers

View.onDraw() --- when does it get called?

I put a Log.d() call into the onDraw() of my extended View, so I could see how often and when it's getting called. It gets called upon instantiation of the view, which is not surprising. But then I notice, it gets called on every tap that is…
CptSupermrkt
  • 6,844
  • 12
  • 56
  • 87
35
votes
3 answers

PorterduffXfermode: Clear a section of a bitmap

The goal is to draw a bitmap and over the top of something, and draw shapes that ERASE the underlying area of the bitmap. I have a proof of concept to try and understand how I should go about this. I have found numerous hints about…
btalb
  • 6,937
  • 11
  • 36
  • 44
22
votes
6 answers

Override onDraw() or draw()?

My project is based on surfaceView and up until now I've had all of my rendering in onDraw which I am overriding. All seemed to be OK. However, I've just updated my SDK and now it gives me an error telling me: Suspicious method call; should…
Zippy
  • 3,826
  • 5
  • 43
  • 96
18
votes
2 answers

Android custom view Bitmap memory leak

I've got a custom view in which I need to draw two bitmaps, one is a background, representing the image of a map and one is a pin which will be drawn on top/left position in canvas. The both images are drawn onDraw and remain the same during the…
Alin
  • 14,809
  • 40
  • 129
  • 218
17
votes
4 answers

How to animate gradient?

How to animate gradient from color#1 to color#2? Something similar to I'm planning to use it as health-bar for unit (so, it will be finit animation starting with green and ending with red)
Nexen
  • 1,663
  • 4
  • 16
  • 44
16
votes
3 answers

Android Multiple SurfaceViews

I'm trying to work with 3 SurfaceViews on one screen, one on top half (BoardView), one on bottom half (StatusView), and the last one as an extra layer above the top half (TileView) (see main.xml). I created a class MySurfaceView, which is extended…
nhaarman
  • 98,571
  • 55
  • 246
  • 278
15
votes
1 answer

onDraw() on View draws behind the layout

Ok, here's the deal. I want to move items in my extended gallery class to change the order of images. The way i'm doing it now: on long press remove the current selected item, use onDraw() to draw the same image so i can move it around using…
Nick
  • 1,733
  • 1
  • 14
  • 24
15
votes
2 answers

Android SweepGradient

I have a SweepGradient defined as circle_paint.setShader(new SweepGradient(getWidth()/2, getHeight()/2, new int[] { circle_start_color, circle_end_color}, new float[] { 0f, 1f})) applied to a arch defined as canvas.drawArc(circle_bounds,…
BOENDAGGER
  • 423
  • 5
  • 21
13
votes
4 answers

Clearing canvas with Canvas.drawColor()

i'm attempting to change the background image of a custom View with some success. the image will change but the problem is that i still see traces of the old image. when i attempt to clear the canvas before drawing the new image, it doesn't appear…
Prmths
  • 2,022
  • 4
  • 21
  • 38
13
votes
2 answers

How to clip a circular path inside a rectangle in Android

I've read over 20 questions/answers but I still can't get what I want. I want to cut a circle inside a rectangle as seen below: Here is my code: @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); …
11
votes
1 answer

Android: Drawing an arc inside a circle

I'm trying to draw an arc inside a circle to represent the temperature, but I'm having a difficult time achieving that. During my search I found those solutions This one I couldn't understand what is the scale method for, and is drawing more than…
Motassem Jalal
  • 1,254
  • 1
  • 22
  • 46
11
votes
2 answers

5.1 like elevation Shadow under a View using onDraw method

I have the following class: class SlidingTabStrip extends LinearLayout { private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 1; private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26; private static final int…
User3
  • 2,465
  • 8
  • 41
  • 84
1
2 3
44 45