MostafaGazar / CustomShapeImageView

A library for supporting custom shaped ImageView(s) using SVGs and paint shapes
http://mostafagazar.github.io/CustomShapeImageView
Apache License 2.0
1.62k stars 425 forks source link

Add Border for the image view #4

Closed shamsundhar closed 9 years ago

shamsundhar commented 9 years ago

Hi Mostafa, I used your Circular ImageView, it was good. But I need to add border for that circular image view. How can I do that. Please help me in resolving this issue. Thanks in advance.

MostafaGazar commented 9 years ago

You can do so by overriding onDraw method in CircleImageView like the following:

private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int cx = getWidth() / 2;
    int cy = getHeight() / 2;
    int strokeWidth = 4;// TODO :: Load from dimensions or take density into account.
    int radius = (getWidth() - strokeWidth) / 2;

    mPaint.setARGB(255, 255, 0, 0);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(4);
    canvas.drawCircle(cx, cy, radius, mPaint);
}