How to draw part of space between two circles in Android - android

I would like to draw in Android something like shape in the picture. I have used Path.drawArc but I can't draw two arcs which are parts of cirlces with the same center. Another problem is how to draw two lines which connect these arcs. In iOS I would use bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:
How to draw shape like in the sketch?

here is simple example using canvas and bitmaps, try this example and get some idea for your requirement. image cropping and transparent

Related

Is there a way in Android to draw a hollow Path on Canvas?

I'm working on an APP in Android and needs to draw things on a Canvas. I want to draw a Path that is hollow, for example something like this image below.
View Image
The Path may contains lines, arcs, bezier curves, etc.
Is there a way for me to achieve that?
I had tried to draw the Path with a thicker Paint first and draw the Path again with a transparent and thinner Paint. But the problem is: there may be other things drawn on the Canvas. Doing so will cover other things intersecting with the Path.
I had also tried to translate the Canvas and draw the Path twice for the two borders. But it turned out that this will not work, for example a parabola (as shown below, it is not what I expected).
View Image
I had tried to draw the Path with a thicker Paint first and draw the Path again with a transparent and thinner Paint. But the problem is: there may be other things drawn on the Canvas. Doing so will cover other things intersecting with the Path.
What do you mean? If the first path-line covers other things drawn, it's ok the inner line would also. If the first line does not cover anything the 2nd line won't cover either.
When do you face the issue of having the first line not cover something while the thinner line does?

Android: draw triangle on top of triangle

I am trying to draw something like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r2.png using android XML shape. It is one big triangle (45° on bottom) and one smaller triangle on top of it. I am planing on using it on image like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r0.png. I know that I could use simple png image of this but I want to set its color programatically so thats why I am trying to use android shape.
Is this too complex to be drawn by shape? If not can you please try to guide me a bit because I really dont know how should I approach this problem.
Thanks in forward
Layer-list should be able to do that. The other way is to extend ImageView and draw what you like on a canvas within the onDraw method.

draw canvas 3d rectangle

I Have extended View class and override draw method. In draw method I draw rectangle using canvas. but this rectangle is simple I need to show as blow. how can I draw rectangle like shown in below image?
create a Path for the top side using 4 points (moveTo and lineTo) and then draw it with Canvas.drawPath. Do the same for the right side
Here is the link for the HoloGraphLibrary. Just check it.
It has no 3d effect as you want but it has Same ui as you want. You will have to play little to have effect like 3d rectangle.
Try a look and let me know if it do not help you.
Enjoy Coding and All The Best. :)

Android: Is it possible to create such type of circle?

I google it but don't know about this which was possible or not to draw circle like this in android using canvas. If possible then how what the way to do this. below is the image.
I don't know any way to create circle in piece format using canvas
I believe that this is possible using Canvas.drawArc with the usecenter parameter set true.
take a look at the android docs
I can think of 3 options:
Create it as a bitmap which you store in your Drawables or Assets then draw it to the canvas. You can scale it as needed when you load it or by scaling the canvas.
You could draw a circle, then draw 3 lines in a different colour to create the "Y" shape, adjusting the thickness of the lines as you need (or use rectangles)
Use an algorithm to calculate the segment then use drawPath to create the segments individually.
[EDIT] Doh! Elemental's solution is much better...
Create 3 different Bipmap
hdip
ldip
mdip
instead of searching or XML

On an android Canvas, how do I draw overlapping shapes with non-interacting alphas?

On an android Canvas, if I draw a circle with alpha 0xCC and color Color.RED and then draw another circle which partially overlaps the first circle with the same parameters, I'll end up with a venn diagram.
Here is a random example I found (just ignore the [Text] in there). I want to draw overlapping circles like in this diagram, but I don't want the center to be darker, but I do want the whole thing to have alpha so that the map underneath is visible.
Is there a way to do this directly or do I need to draw to a bitmap without alpha and then set the alpha for the whole bitmap and draw it to a canvas? (I haven't used bitmaps yet, so I am not sure how they are used yet.)
The easy way would be your suggested solution, ie. drawing all circles with no alpha to a bitmap, then draw that bitmap to another one using the desired alpha.
The hard way would be using blend modes, specifically PorterDuff.Mode in Android. An example can be found here.

Categories

Resources