我有一个项目,我以编程方式将自定义地图标记添加到地图活动。当用户单击标记时,BottomSheetDialog 会从屏幕底部出现,其中包含有关自定义地图标记的信息。关键信息之一是将播放的视频。问题是 VideoView 的 MediaController 没有悬停在视频上方,而是在 BottomSheetDialog 后面。它位于屏幕上的正确位置,但位于 BottomSheetDialog 和 VideoView 的后面。我正在使用 EpoxyRecyclerView 将 VideoView、MediaController 和各种 TextView 添加到 BottomSheetDialog。
创建 BottomSheetDialog 的函数:
override fun onMarkerClick(marker: Marker): Boolean {
val modalSheetView = layoutInflater.inflate(R.layout.activity_page_details, null)
val bottomSheetDialog = BottomSheetDialog(this)
bottomSheetDialog.setContentView(modalSheetView)
pageController.page = marker.tag as Page
val epoxyRecyclerView = bottomSheetDialog.findViewById<EpoxyRecyclerView>(R.id.pageDetailsRecyclerView)
epoxyRecyclerView?.setControllerAndBuildModels(pageController)
bottomSheetDialog.show()
bottomSheetDialog.setOnDismissListener { it.dismiss() }
// Return false to indicate that we have not consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move such that the
// marker is centered and for the marker's info window to open, if it has one).
return false
}
将 VideoView 和 MediaController 添加到 BottomSheetDialog 的 Epoxy 函数:
data class PageVideoEpoxyModel(
val videoUrl: String
):ViewBindingKotlinModel<ActivityPageVideoBinding>(R.layout.activity_page_video){
override fun ActivityPageVideoBinding.bind() {
videoView.setVideoURI(Uri.parse(videoUrl))
videoView.setOnPreparedListener {
val mediaController = MediaController(videoView.context)
mediaController.setMediaPlayer(videoView)
mediaController.isEnabled = true
videoView.setMediaController(mediaController)
mediaController.setAnchorView(videoView)
mediaController.requestFocus()
videoView.start()
mediaController.show(0)
}
}
}
VideoView 的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="210dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:clickable="true"/>
</androidx.constraintlayout.widget.ConstraintLayout>
EpoxyRecycler 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.airbnb.epoxy.EpoxyRecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pageDetailsRecyclerView"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</androidx.constraintlayout.widget.ConstraintLayout>