I want to draw with canvas a radius on top of middle like below
How can I draw a radius like I marked on picture
Related
I am trying to draw the following shape in a circle on a canvas. I know how to draw a circle using the center, radius and paint variable. But I am trying to draw the figure below.
I have a circle object, created with OpenGL vertices.
When the circle is being touched, I want a scaling animation to be activated. The circle radius will grow bigger until it reaches a certain radius, and then the circle will transform back to its original radius.
What is the best way to implement this animation?
You have a few possibilities. The simplest would be to just create a variable which would hold a scaling factor for your circle and multiply all vertices by it before rendering. Then using some timers and adjusting the scaling factor in time, you could create your animation.
I should add that if you want to scale your circle by its center then you have to first translate the circle vertices so that circle's center will be at (0, 0) point, then scale by the factor and translate the circle back to its initial position.
If the circle animation you're trying to implement is some kind of your GUI element then another way which comes to my mind is to:
create an ImageView in xml or dynamically in code
draw the vertices on it
create an XML android animation and apply it whenever you want
Here's a draft of the code for drawing a circle on the ImageView:
Bitmap tempBitmap = Bitmap.createBitmap(yourCircleWidth, yourCircleHeight, Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(tempBitmap);
//Draw the circle into the canvas
tempCanvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
tempCanvas.drawCircle(circleCenterX, circleCenterY, yourCircleRadius, paint);
//Attach the canvas to the ImageView
yourImageView.setImageDrawable(new BitmapDrawable(yourImageView.getResources(), tempBitmap));
For XML animations, here's a good reference:
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
I wanted to draw a rectangle with rounded corners in OpenGL|ES.
The user will input 3 things:
Coordinates of top left corner (X1,Y1).
Coordinates of bottom right corner (X2,Y2).
radius for the roundness of the corner (r).
The approach I am currently taking is that I will draw 3 rectangles based on the input given by the user and then will draw four arcs on each of the four corners of the rectangle.
is it the right way of doing it or is there some better approach for this ?
Is that possible to draw text on Canvas with gradient color in Andorid?
For example, draw letter A with top part is red while bottom part is blue?
Thanks
I am using android java to create an application that uses the accelerometer, i have created a shape that does kinda move with the accelerometer but it stays in the top left hand corner and moves there, can anyone help me with how can i move it to the center of the screen and set bounds
I am assuming you are using a canvas to draw that stuff if so canvas has a method called getwidth() and also getheight()
what you can do is when you are drawing it to the canvas set the location point x and y coordinates as
canvas.getWidth()/2
and canvas.getHeight()/2
something like this
canvas.drawBitmap(bitmap, canvas.getWidth()/2, canvas.getHeight()/2, null);
I hope you got the idea.
canvas.drawRect(left, top, right, bottom, paint)
use this function if you wanna draw a rectangle
Parameters:
left The left side of the rectangle to be drawn
top The top side of the rectangle to be drawn
right The right side of the rectangle to be drawn
bottom The bottom side of the rectangle to be drawn
paint The paint used to draw the rect
Use the same logic in this method and you are golden ;)