下面是一个使用xml drawable和渐变为ImageView添加类似边框的示例代码:
ImageView imageView = findViewById(R.id.imageView);
GradientDrawable gradientDrawable = new GradientDrawable(
GradientDrawable.Orientation.BL_TR,
new int[]{Color.parseColor("#FF00FF"), Color.parseColor("#00FF00")}
);
gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setCornerRadius(10);
imageView.setBackground(gradientDrawable);
这样,ImageView将具有一个类似边框的外观,并且背景为渐变颜色。你可以根据需要调整边框的宽度、颜色和圆角半径,以及渐变的颜色和方向。