最近做了一个项目,需要播放一段小视频,做用户引导功能,就使用了Android 自带的VideoView,在与MediaController结合使用的时候,MediaController控制栏总是出现在底部,在网上也搜了其他的解决方案,有在代码中设置位置的如:
mediaController.setPadding(0,0,0,bottom);
但是我在使用的时候,好像没有效果。只能翻看源码了,在源码中发现,MediaController的位置根据VideoView所在的父控件的位置设置的,而我的VideoView的父控件就是Activity所使用的控件,以至于无论我怎么修改总是出现在Activity的底部,所以我在VideoView 外层加了一个RelativeLayout,这样MediaController的位置,就在Video View的底部了,完美解决;
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/def_layout_bg2"
android:orientation="vertical">
....
<RelativeLayout
android:layout_margin="20dp"
android:layout_height="200dp"
android:layout_width="match_parent">
<VideoView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/video_view"
/>
</RelativeLayout>
......
</LinearLayout>
video_view.setVideoPath("https://*****.MP4");
MediaController mediaController = new MediaController(this);
video_view.setMediaController(mediaController);
mediaController.setMediaPlayer(video_view);
video_view.start();