Android MediaController的位置控制

最近做了一个项目,需要播放一段小视频,做用户引导功能,就使用了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();

 

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值