圆形快速联系挂件 [英] Circular Quick Contact Badge

查看:111
本文介绍了圆形快速联系挂件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我一有快速联系联系人列表视图badge.It显示方形的图像,但我的要求是显示圆形快速联系挂件(如下面的屏幕截图)。 PLZ让我知道我能做到这一点。先谢谢了。

Hi guys I a have contact list view with Quick contact badge.It displaying square images but my requirement is to show circular quick contact badge (like below screen shot). Plz let me know how can I achieve this. Thanks in advance.

推荐答案

下面是两种方法来创建圆形的图像。你只需要通过位图图像,使其循环。

Below are two methods for creating circular images. you just have to pass bitmap image to make it circular.

/**
 * To make image in a round shape. Use this method if you want to specify required height and width
 * 
 * @param i
 */
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int i) {
    int targetWidth = i;
    int targetHeight = i;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2,
            ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
            Path.Direction.CCW);
    canvas.clipPath(path);
    Bitmap sourceBitmap = scaleBitmapImage;
    canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
            targetHeight), null);
    return targetBitmap;
}

/**
 * To make image in a round shape
 */

public static Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    // Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
    // return _bmp;
    return output;
}

这篇关于圆形快速联系挂件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆