如何在自定义imageview中添加边框



我正在与android合作。我创建了一个带有自定义图像视图的android应用程序,它可以剪切图像的各个角落。这是我的自定义图像视图

public class CustomImage extends ImageView {
    public static float radius = 18.0f;  
    public CustomImage(Context context) {
        super(context);
    }
    public CustomImage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
            CustomImage.this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        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);
    }
}

它工作完美。但是我需要在剪辑后的图像视图周围添加边框,我该怎么做呢?

如果你想要圆角,你可以使用这个库RoundedImageView。您可以看到库的代码,以便您可以实现。

或本教程圆角

最新更新