简体   繁体   中英

rounded corner videoview in android java

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.

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.

Have a nice day!

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM