android bitmap gradient in android 2.1
Is there a way to put a gradient to a bitmap object in android 2.1? The image must look like this:
I need the gradient only on to开发者_运维技巧p of the bitmap. DrawableGradient or LinearGradient are only from android 2.2 so these objects doesn't help me at all. Thanks
Do you need this from XML or from code? In code, try this:
/* Create a 200 x 200 bitmap and fill it with black. */
Bitmap b = Bitmap.createBitmap(200, 200, Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawColor(Color.BLACK);
/* Create your gradient. */
LinearGradient grad = new LinearGradient(0, 0, 0, 50, Color.GRAY, Color.BLACK, TileMode.CLAMP);
/* Draw your gradient to the top of your bitmap. */
Paint p = new Paint();
p.setStyle(Style.FILL);
p.setShader(grad);
c.drawRect(0, 0, 200, 50, p);
In XML, just make two separate views in a vertical linear layout. The top view should have a gradient drawable background, the bottom, taller view should have a solid background.
精彩评论