Android:如何在com.facebook.widget.ProfilePictureView上放置圆角

时间:2013-06-06 08:01:54

标签: android facebook

我想问你如何把圆角放在上面 com.facebook.widget.ProfilePictureView。

我尝试使用

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners android:radius="50dip" />
    <solid android:color="#dd7b7a"/>

</shape>

和android:background =“@ drawable / rounded_shape”,但圆角部分在图像外部(ProfilePictureView是FrameLayout),图像本身没有圆角。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

以下代码返回带圆角的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;
}