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

两盒软妹~` 提交于 2019-12-17 22:03:05

问题


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?


回答1:


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.




回答2:


I think there is no easy way to do this. You could try this for example:

  • place a video window under a ImageView window
  • populate the ImageView with a solid color PNG that has a transparent shape in it
  • use a FrameLayout or RelativeLayout to hold the two views as they allow views to overlap each other easily



回答3:


You can easily achieve this effect by putting a TextureView inside a CardView (from the support library).

You can then set corner radius and shadow on the CardView:

<androidx.cardview.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardCornerRadius="12dp">

    <TextureView
        android:id="@+id/video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</androidx.cardview.widget.CardView>


来源:https://stackoverflow.com/questions/23300612/how-should-i-override-videoviews-ondraw-in-order-for-it-to-have-transparent-rou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!