我正在开发视频播放器,我需要在我的视频 View 上显示 SeekBar、当前时间 TextView 、视频长度 TextView 。我还需要将其放入具有透明背景的任何布局中。我已经在 Stackoverflow 中阅读了一些主题,但它们对解决我的问题没有帮助。谁能帮帮我!非常感谢! 这是我的视频播放器的 xml 布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_main_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- This is Layout that must be in the top of my video view --->
<LinearLayout
android:id="@+id/streams"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#40ffffff"
android:orientation="horizontal"
android:visibility="gone" >
<Spinner
android:id="@+id/language_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/subtitle_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:id="@+id/full_screen"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1"
android:src="@drawable/logo_fullscreen" />
</LinearLayout>
<!-- This is layout with seekbar and text views with current time, video file length -->
<!-- I need to show it on the bottom of my video view -->
<RelativeLayout
android:id="@+id/controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:backgroundDimEnabled="true"
android:background="#00ffffff"
>
<Button
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_media_play"
android:contentDescription="@null"
android:enabled="false" />
<Button
android:id="@+id/scale_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/play_pause"
android:background="@android:drawable/ic_menu_info_details"
android:enabled="true" />
<SeekBar
android:id="@+id/seek_bar"
android:alpha="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/scale_type" />
<TextView
android:layout_margin="3dp"
android:id="@+id/current_time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seek_bar"
android:layout_alignLeft="@+id/seek_bar"
android:text="" />
<TextView
android:layout_margin="3dp"
android:id="@+id/video_length_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seek_bar"
android:layout_alignRight="@+id/seek_bar"
android:text="" />
</RelativeLayout>
<!-- This is my VideoView, all controls I must display over it --->
<com.ffmpeg.FFmpegSurfaceView
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/controls"
android:layout_below="@+id/streams"
android:visibility="visible" />
</RelativeLayout>
最佳答案
您在实现所有其他操作后实现您的视频 View 。如果您使用的是 RelativeLayout,则应首先添加 videoView,然后在其上添加 SeekBar。
类似下面的内容:
<LinearLayout
android:id="@+id/streams"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#40ffffff"
android:orientation="horizontal"
android:visibility="gone" >
<Spinner
android:id="@+id/language_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/subtitle_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:id="@+id/full_screen"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1"
android:src="@drawable/logo_fullscreen" />
</LinearLayout>
<!-- This is layout with seekbar and text views with current time, video file length -->
<!-- I need to show it on the bottom of my video view -->
<com.ffmpeg.FFmpegSurfaceView
android:layout_below="@+id/streams"
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
<RelativeLayout
android:id="@+id/controls"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#33000000" >
<Button
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@android:drawable/ic_media_play"
android:contentDescription="@null"
android:enabled="false" />
<Button
android:id="@+id/scale_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/play_pause"
android:background="@android:drawable/ic_menu_info_details"
android:enabled="true" />
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/scale_type"
android:alpha="0.5" />
<TextView
android:id="@+id/current_time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/seek_bar"
android:layout_below="@+id/seek_bar"
android:layout_margin="3dp"
android:text="" />
<TextView
android:id="@+id/video_length_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/seek_bar"
android:layout_below="@+id/seek_bar"
android:layout_margin="3dp"
android:text="" />
</RelativeLayout>
<!-- This is my VideoView, all controls I must display over it - -->
关于安卓。在另一个布局上的透明布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21546678/