You need to write a custom Drawable class and assign it to your ImageView. Then you can do this easily in the draw method like this:
class MyDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
Path path = new Path();
path.setFillType(FillType.EVEN_ODD);
// This will create a full screen rectangle.
path.addRect(<screen size rect here>, Path.Direction.CW);
// This will punch a hole in it
path.addCircle(<x>, <y>, <radius>, Path.Direction.CCW);
// Now draw everything on the Canvas
Paint paint = new Paint();
paint.setColor(<dim color here>);
canvas.drawPath(path, paint);
}
To make it work nicely when highlighting, you can pass the View you want to highlight in this Drawable's constructor. Then you can determine the position of the view using:
int[] position = new int[2];
view.getLocationOnScreen(position);
Use this and the view's height and width to determine the size and position of the circle.
I don't know if this will work, but you can also try feathering the cutout by doing this:
paint.setMaskFilter(new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL));