安卓设置videoview全屏

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/nvcxy_1225/article/details/50513282

之前做一个播放器。videoview一直没法全屏。真的是搜了一些资料什么的。后来在一个网站上看到大神的解答。试了一下果然是有效的。择出部分关键代码。



boolean fullscreen = false;
if(!fullscreen){//设置RelativeLayout的全屏模式
RelativeLayout.LayoutParams layoutParams=
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mVideoView.setLayoutParams(layoutParams);

fullscreen = true;//改变全屏/窗口的标记
}else{//设置RelativeLayout的窗口模式
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(300,400);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
mVideoView.setLayoutParams(lp);
fullscreen = false;//改变全屏/窗口的标记
}




布局


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.23" >
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>

展开阅读全文

没有更多推荐了,返回首页