Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

android - How should I override VideoView's onDraw in order for it to have transparent rounded corners?

Clearly using a background shape doesnt work in the case of VideoView Also, there are lots of articles how to override onDraw for ImageView and make its corners round.

But how do I do it for a VideoView?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Transparent rounded corners cannot be done with a VideoView or any SurfaceView, as according to the documentation:

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed.

With a TextureView it seems theoretically possible, as its supposed to behave like a normal view. However I was unable too: Tried Porter Duff modes of both the TextureView layer paint and a ShapeDrawable in the foreground of the parent FrameLayout.

With a VideoView, what you can do is make corners of a solid color. Use a 9-patch with transparent content and just the corners of a solid color and set in on an ImageView that gets drawn on top.

Edit: Check this example project.

screenshot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...