我想在具有 140dp 高度的 BottomSheetDialogFragment 中的 VideoView 中加载视频,但是当我打开对话框时,视频正在屏幕顶部播放
BottomSheetDialogFragment:
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="140dp" />
<TextView
android:id="@+id/txt_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_gravity="center"
android:layout_marginTop="23dp"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:textColor="@color/black"
android:letterSpacing="0.01"
android:text="dummy_large_text"
android:lineSpacingExtra="6.5sp"
tools:ignore="RtlSymmetry"
tools:targetApi="lollipop" />
<Button
android:id="@+id/btn_back"
android:layout_width="match_parent"
android:layout_height="60.2dp"
android:textColor="@color/white"
android:layout_marginTop="21.5dp"
android:text="@string/back"
android:background="@color/colorPrimary"
android:letterSpacing="0.09"
tools:targetApi="lollipop" />
</LinearLayout>
Java 代码:
holder.videoView.setVideoURI(Uri.parse(imgPathFile + File.separator + dataModels.get(position).getFileName()));
holder.videoView.setMediaController(new MediaController(context)); //sets MediaController in the video view
holder.videoView.requestFocus();//give focus to a specific view
holder.videoView.start();//starts the video