3

In my application, I want to display videoview as a rounded corners. I have tried placing videoview/surfaceview inside linearlayout with rounded corner set to linearlayout. but it does not work perfectly. I can not set rounded corner to videoview/surfaceview. I want to set view as below image: enter image description here

Anyone have idea how to do this?

Mihir Shah
  • 1,799
  • 3
  • 29
  • 49

9 Answers9

7

Not sure why there are so many bad answers when the solution is really simple (as long as you're min sdk > 21). Creating a shape and putting it overtop of the video won't work because you obviously want the background to be transparent to see the views behind it.

I found the answer here Android View Clipping. You just put the video view in a frame layout, add a rounded background to the frame layout, add an outline provider and clip the frame layout to the outline.

The background rounded_video_background:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#000000"/>
    <corners android:radius="16dp" />

</shape>

The frame layout and video view inside of it:

<FrameLayout
        android:id="@+id/video_view_container"
        android:layout_width="90dp"
        android:layout_height="120dp"
        android:background="@drawable/rounded_video_background"
        android:outlineProvider="background">

        <VideoView
            android:id="@+id/video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            />

    </FrameLayout>

And the final step is clipping to the outline (didn't see a way to do it in xml so I did it programatically): video_view_container.clipToOutline = true

odiggity
  • 1,496
  • 16
  • 29
5

Its worked for me,

        <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        card_view:cardCornerRadius="25dp"
        android:layout_height="wrap_content">
    <VideoView
        android:id="@+id/video"
        android:layout_width="match_parent"
        android:layout_height="215dp" />
    </android.support.v7.widget.CardView>
  • 3
    The card view is garbage because the inner video view, it doesn't have a corner radius, the square will come out. – CodingTT Nov 07 '19 at 20:47
1

You can make it using a FramLayout & an XML drawable

FramLayout

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <VideoView
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp_240"
                android:layout_margin="@dimen/dp_24"/>

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/rounded_corner_video_bg" />
        </FrameLayout>

XML Drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:width="@dimen/dp_24"
        android:color="@color/md_white_1000" />
    <corners android:radius="@dimen/dp_24" />
</shape>
Nilesh Rathore
  • 886
  • 1
  • 12
  • 22
0

You could try layering different views on top of each other to create the rounded corners you are looking for. Try placing four ImageViews over the VideoView in each corner, to achieve the desired rounded corners. I have had success using a RelativeLayout to accomplish this, but you could also try using a FrameLayout to hold the Views together.

frgnvola
  • 518
  • 3
  • 16
0

It is directly not possible, but you can do this by draw a imageview on top of videoview and set an image having transparent from between and solid color in rounded shape on the corners. check this: Click here

Community
  • 1
  • 1
Rahul Sharma
  • 5,949
  • 5
  • 36
  • 46
0

Its simple, 1. Create a drawable with rounded corners as mentioned by @sunil kumar 2. Set that drawable to your layout as a background 3. When using that layout set layout(your layout item name).clipToOutline = true

Akshay Chouhan
  • 335
  • 3
  • 6
0

This is XML code of rounded VideoView.

<androidx.cardview.widget.CardView
            android:id="@+id/videoCard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="16dp"
            app:cardCornerRadius="20dp"
            card_view:cardBackgroundColor="@color/white">

            <VideoView
                android:id="@+id/relativeVideo"
                android:layout_width="match_parent"
                android:layout_height="225dp"
                android:paddingTop="-10dp"
                android:paddingBottom="-10dp" />
        </androidx.cardview.widget.CardView>

Negative padding is important otherwise height of VideoView is smaller than cardview by half of cornerRadius in both top and bottom side. You can set height whatever you want but negative padding should be half of cardCornerRadius all the time. Purple in the image is a video preview, not related to xml.

Have a nice day!

enter image description here

Aykut Uludağ
  • 1,876
  • 5
  • 18
  • 34
-3

Create an xml file in drawable folder called shape_video.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
       <corners android:radius="6dp" />
 </shape>

Change the radius according to your rqmnt and in the background attribute of your videoview, give

android:background="@drawable/shape_video"
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
Parijat Bose
  • 380
  • 1
  • 6
  • 22
-3

put rounded.xml in your drawable folder and set on framelayout of video like android:background="@drawable/rounded.xml"

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">

    <solid android:color="#FFFFFFFF" />
    <corners android:radius="7dp" />

</shape>
Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
  • I used your code, set above to framelayout background, but its not working. only problem for videoview/surfaceview, not for any other components. – Mihir Shah Jun 17 '13 at 13:15