我已覆盖图像绘制方法以在AppCompatImageView
上绘制边框。
对于某些图像可以正常工作,但对于某些图像,图像上方和下方有一些空白区域,如下图所示。我想在图像尺寸上精确绘制边框。
以下是代码
private static final int PADDING = 8;
private static final float STROKE_WIDTH = 8.0f;
private Paint mBorderPaint;
private void initBorderPaint() {
mBorderPaint = new Paint();
mBorderPaint.setAntiAlias(true);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setColor(Color.WHITE);
mBorderPaint.setStrokeWidth(STROKE_WIDTH);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(PADDING, PADDING, getWidth() - PADDING, getHeight() - PADDING, mBorderPaint);
}