Question

According to Android developer docs :

Shader is the based class for objects that return horizontal spans of colors during drawing. A subclass of Shader is installed in a Paint calling paint.setShader(shader). After that any object (other than a bitmap) that is drawn with that paint will get its color(s) from the shader.

But I don't understand that definition. Could you guys please tell me what is shader in android in simple terms? Also, what is the meaning of "horizontal spans of colors"?

Thanks a lot.

Was it helpful?

Solution

A shader allows to define for a Paint object the content which should be drawn.

For example you can use a BitmapShader to define that a bitmap should be used to draw. This allows you for example to draw an image with rounded corners. Simply define a BitmapShader for your Paint object and use the drawRoundRect() method to draw a rectancle with rounded corners.

Other Shaders provided by the Android platform are LinearGradient, RadialGradient and SweepGradient for drawing color gradients.

To use a Shaders assign it to your Paint object via the setShader() method.

If the area which is filled is larger than the Shaders you can define via the Shader tile mode how the rest should be filled.

The Shader.TileMode.CLAMP constant defines that the edge corners should be used to fill the extra space. 
The Shader.TileMode.MIRROR constant defines that the image is mirrored.
The Shader.TileMode.REPEAT defines that the image will be repeated. 

Source: Vogella

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top