向RoundedNetworkImageView添加边框

时间:2015-11-19 13:13:14

标签: android border android-imageview networkimageview

我正在使用RoundedNetworkImageView。我想为它添加一个1 dp的边框。如果我创建一个单独的drawable并将其作为背景放到RoundedNetworkImageView然后它替换了视图的圆度。我如何更新下面的代码来添加边框到imageview? 以下是我正在使用的代码 -

public class RoundedNetworkImageView extends NetworkImageView {
    public CWRoundedNetworkImageView(Context context) {
        super(context);
    }
    public CWRoundedNetworkImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CWRoundedNetworkImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
    }
    @Override
    public ScaleType getScaleType() {
        return ScaleType.CENTER_CROP;
    }
    @Override
    protected void onDraw(Canvas canvas) {
        float radius = 12.0f;
        Path clipPath = new Path();
        RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
        clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}

0 个答案:

没有答案