2016-04-28 38 views
1

这是我的非工作代码:如何在GradientDrawable上绘制位图?

GradientDrawable sh = new GradientDrawable();   // create a gradient drawable.   
Bitmap cbm = bmp.copy(Bitmap.Config.ARGB_8888, true); // do not use an immutable bitmap. 

Canvas cv = new Canvas(cbm); //create a canvas using the mutable bitmap. 

sh.setAlpha(255); // this has no effect? 
sh.draw(cv);  // does nothing? 

sh.setStroke(thik, clr);  //this works fine. 
sh.setCornerRadius(radius); // This works fine. 

v.setBackgroundDrawable(sh); // displays a rounded corner box with transparent center (no bitmap!!). 

我敢肯定,我做错了什么,但我不知道我做错了。我希望这不是Java代码将一个简单的函数调用转换为一个完整的事件,并用消息来捕获和填充的东西。

帮助?

基本上我需要的是一个有点圆角的按钮,中心有2或3像素的笔画和拉伸的位图(圆角笔势角应该覆盖位图的边角)。

感谢。

回答

0

设置你的GradientDrawable的界限:

Canvas cv = new Canvas(cbm); 

sh.setBounds(<x>, <y>, <w>, <h>); 

sh.setAlpha(255); 
sh.draw(cv);