如何从VideoView中删除黑色视图?

问题描述 投票:0回答:1

我在里面使用了教程视频

VideoView
。但是视频在播放时不会填充
VideoView
并且
VideoView
中有黑色部分,因为它具有矩形视图。我无法解决它。我尝试用
VideoView
覆盖
CardView
并制作 cardRadius。但它并没有正确去除所有黑色部分。怎么能做到这一点呢?无法制作
VideoView
background
半径吗?

enter image description here

视频片段.kt

private fun initVideo() {
    simpleVideoView = binding.videoViewTutorial
    simpleVideoView?.setVideoURI(
        Uri.parse("android.resource://" + requireActivity().packageName + "/" + R.raw.tutorial)
    )
    simpleVideoView?.requestFocus()
    simpleVideoView?.start()

}

fragment_video.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/tabContainerUser"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_gravity="bottom"
        android:layout_margin="30dp"
        android:background="@drawable/background_white_gray_stroke_60dp_radius"
        app:itemIconSize="27dp"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu_user" />

    <ImageView
        android:id="@+id/ivAskAdvise"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:translationZ="999dp"
        android:src="@drawable/ic_black_plus_yellow_bg"
        app:layout_constraintBottom_toBottomOf="@+id/bottomNavigationView"
        app:layout_constraintEnd_toEndOf="@+id/bottomNavigationView"
        app:layout_constraintStart_toStartOf="@+id/bottomNavigationView"
        app:layout_constraintTop_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintVertical_bias="0.63"
        tools:ignore="ContentDescription" />

    <View
        android:id="@+id/viewBlackBg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black_0_70"
        android:visibility="gone"
        android:translationZ="999dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="visible" />

<!--    <androidx.cardview.widget.CardView
        android:id="@+id/cardViewVideo"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:cardCornerRadius="70dp"
        app:cardBackgroundColor="@color/transparent"
        android:visibility="gone"
        android:translationZ="999dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.80"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.80"
        tools:visibility="visible">-->

    <VideoView
        android:id="@+id/videoViewTutorial"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:translationZ="999dp"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.80"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.80"
        tools:visibility="visible"/>

    <!--</androidx.cardview.widget.CardView>-->

    <TextView
        android:id="@+id/tvSkipTutorial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:fontFamily="@font/mulish_regular"
        android:text="@string/skip"
        android:textColor="@color/white"
        android:textSize="16sp"
        android:visibility="gone"
        android:translationZ="999dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/videoViewTutorial"
        tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
android kotlin android-layout android-videoview
1个回答
0
投票

试试这个

vSimpleVideoView.setBackgroundColor(Color.TRANSPARENT);
© www.soinside.com 2019 - 2024. All rights reserved.