I drawing a lines from point to point with gradient. To everything looks nice I using rounded caps between them. Problem is that caps are only in one colour. There is possibility to paint them separately or force drawing to do it right?
Or maybe just draw a dot between them?
I found solution.
Like I write before I just gonna draw my own Points between the lines and put there whatever colour I need.
You should use the GradientDrawable with the LINE shape,
Documentation: http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html
Related
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?
I am looking to dynamically create (bezier) curves in Android using Canvas and Paint. I can easily do nice curves with setStrokeWidth or doing a more complex polygon/path.
But how can I make the gradient follow the curve like in this example? LinearGradient in either direction would not give the same feel.
In some parts of the curve there is a narrower gradient as well.
Is it made by some inner shadow or maybe just redrawing lots and lots of curves?
I'm afraid curving the gradient is not possible using the built-in gradient classes (LinearGradient, RadialGradient, SweepGradient). It's possible to draw lots of curves, but that would basically mean writing the curved gradient yourself. :)
(And the shading of the surface looks a bit even more subtle to me, resembling a 3D render.)
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, 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.
I'm trying out the android graphics classes.
I wanted to draw some arcs/circles with a fill color and black outline.
The Paint class has a style for FILL_AND_STROKE, but there doesn't seem to be a way to set the fill color vs. stroke color. So as far as I can tell it's the same as FILL?
So what's the point of FILL_AND_STROKE if you can't set a separate fill and stroke color?
I haven't managed to find a good explanation.
(I solved my simple problem by doing a fill first, then a stroke, naturally)
Edit:
I ran into this bug report: http://code.google.com/p/android/issues/detail?id=4086
Comment 4 and 5 seem to imply that FILL_AND_STROKE is basically the same as FILL and it will be 'fixed' in 2.2. I guess they'll add a new color?
afaik: FILL fills your circle, while FILL_AND_STROKE also draws the border. If you increase the size of the stroke, it should result in different circles sizes (only visual!)
Think about this: you draw a circle by hand with a small sized pencil. The radius is what you wanted. If you now take a big brush and draw the circle again, your radius is much bigger... (i hope its understandable O.o )
I guess the FILL_AND_STROKE is particularly useful, if one would animate between STROKE and FILL, while wanted to retain the size of the drawn object.
I'm giving an example with the first one below is animated between FILL_AND_STROKE to STROKE, while the second is on just FILL to STROKE. You could easily see the size shrink.
Hence FILL_AND_STROKE is pretty handy here to make size as consistent as possible with others that have STROKE, without have to manually adjust the size of the drawn object (which is complicated)
Yes it's a bit silly. The only use for it is if you want to change between a stroke only and a filled circle then you can use FILL_AND_STROKE to keep the size of the circle the same.
If you went from STROKE to FILL you would lose the width of the stroke when you drew the circle again.
If your stroke style is something other than a solid line (eg a dashed line), you should be able to see the difference. Not that it seems a very useful feature though.
Being able to extend the silhouette of something (more complex than a circle) outwards can be extremely useful though, and not easily obtained by other means
Please see #Shurane's comment.
Just draw it twice, one filled, one stroke and each with one color.
Worked great for me, and gives the impression of a STROKE and a FILL!