以下代码返回带有圆角的 Drawable。也许你可以得到图片,圆角,然后再把它放进去(我不知道 facebook 小部件是如何工作的,所以我只是在猜测):
public static BitmapDrawable getRoundedRectBitmap(Bitmap bitmap, int pixels)
{
int color;
Paint paint;
Rect rect;
RectF rectF;
Bitmap result;
Canvas canvas;
float roundPx;
result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(result);
color = 0xff424242;
paint = new Paint();
rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
rectF = new RectF(rect);
roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
@SuppressWarnings("deprecation")
BitmapDrawable bitmapDrawable = new BitmapDrawable(result);
return bitmapDrawable;
}