how to add gradient to my rectangle shape dynamically in android? - android

I have created rectangle shapes using onDraw method, filled with single colors. Now I have a requirement to add gradient effects to those rectangles. Now I have to fill each rectangle with multiple colors(i.e gradient effect). Could some one suggest me the way to do that. Any response would be great.
thanks in advance.

See the LinearGradient class in the Android graphics library.

Related

How To make a circle like this using canvas in Andriod

The problem is to make a circle which has more then one semi circles and having some text on that emi circle depends upon my text input array. how to make this in canvas.
You can use great MPAndroidChart library.
It supports circle graphs.

Create curved gradients with `Paint` and `Canvas`

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.)

Andengine: How to draw a transparent rectangle with rounded corners and border?

I've been trying to figure out how to draw a transparent rectangle with rounded corners and border with no avail.
Being new to andengine, I'm wondering if it is possible at all. Can someone please provide some pointers or help with a link to a sample. Wasn't able to find any when searching over the internet.
There already Rectangle class in andengine..
Rectangle rec=new Rectangle(x,y,width,height,....);
For transparency:
rec.setAlpha(0):
Attach to your scene, if you are using rectangle as physics object like used for collision then create box body from PhysicsFactory.createBoxBody();
scene.attachChild(rec);
Instead of using a Rectangle can you use a Sprite. Just create an image in Photoshop or another program, apply some transparency and export as .png. Then just load the image as Sprite.

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.

canvas drawing issue where paint needs to be restricted by black sketch

I need to create the painting application for the kids where kid can colour inside the black bordered sketch of any image
But, I am struck with the problem,that colouring can come outside the black bordering of the image...which i don't want to.Please guys help me to find out how to restrict the colouring by user within the black border of sketch
Also, I want that no colour should cover the black border.it should be inside the border.
I can post my code if required.
Look at Canvas clipPath and use the clipping built in to android to limit the 'coloring' of the kid/user to the regions you specify. You can then draw your objects as layers, kid/user colored layer on bottom, your sketch on top.
Finally..i have implemented it using mask bitmap and right usage of Portet.Duff mode

Categories

Resources