我正在使用 RoundedNetworkImageView。我想为它添加一个 1 dp 的边框。如果我创建一个单独的可绘制对象并将其作为 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);
}
}