我想在我的活动中使用VIDeoVIEw播放视频,并在单击按钮时使其成为全屏和横向模式(带有隐藏的虚拟按钮和状态栏).
但是它无法隐藏虚拟按钮,并且底部有一条白线.
This my activity code:
public class VIDeoActivity extends Activity {private VIDeoVIEw mVIDeoVIEw;private String mUrl;private button mFullScreen;private static String TAG = VIDeoActivity.class.getname();@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentVIEw(R.layout.vIDeo); mVIDeoVIEw = (VIDeoVIEw) findVIEwByID(R.ID.vIDeo); mFullScreen = (button) findVIEwByID(R.ID.fullscreen); file file = new file(Environment.getExternalStorageDirectory(),"vIDeo.mp4"); mVIDeoVIEw.setVIDeoPath(file.getPath()); mVIDeoVIEw.start(); mFullScreen.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { enterFullScreen(); mFullScreen.setVisibility(VIEw.GONE); } });}@OverrIDeprotected voID onDestroy() { super.onDestroy(); Log.d(TAG,"onDestroy");}private voID enterFullScreen(){ getwindow().setFlags(WindowManager.LayoutParams.FLAG_FulLSCREEN,WindowManager.LayoutParams.FLAG_FulLSCREEN);//设置全屏 this.setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置横屏 getwindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//常亮 relativeLayout.LayoutParams layoutParams = new relativeLayout.LayoutParams( relativeLayout.LayoutParams.MATCH_PARENT, relativeLayout.LayoutParams.MATCH_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); }}
vIDeo.xml
<?xml version="1.0" enCoding="utf-8"?> <relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <VIDeoVIEw androID:ID="@+ID/vIDeo" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:padding="0dp"/> <button androID:ID="@+ID/fullscreen" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:visibility="visible" androID:text="Fullscreen"/></relativeLayout>
解决方法:
在横向模式下尝试此 *** 作.
<VIDeoVIEw androID:ID="@+ID/vIDeo" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_alignParentleft="true" androID:layout_alignParentRight="true" androID:layout_alignParentBottom="true" androID:layout_alignParenttop="true" />
隐藏虚拟按钮添加以下代码:
getwindow().getDecorVIEw().setsystemUIVisibility(VIEw.SYstem_UI_FLAG_HIDE_NAVIGATION);
原始尺寸
displayMetrics metrics = new displayMetrics(); getwindowManager().getDefaultdisplay().getMetrics(metrics); androID.Widget.linearLayout.LayoutParams params = (androID.Widget.linearLayout.LayoutParams) vIDeoVIEw.getLayoutParams(); params.wIDth = (int) (300*metrics.density); params.height = (int) (250*metrics.density); params.leftmargin = 30; vIDeoVIEw.setLayoutParams(params);
全屏尺寸
displayMetrics metrics = new displayMetrics(); getwindowManager().getDefaultdisplay().getMetrics(metrics); androID.Widget.linearLayout.LayoutParams params = (androID.Widget.linearLayout.LayoutParams) vIDeoVIEw.getLayoutParams(); params.wIDth = metrics.wIDthPixels; params.height = metrics.heightPixels; params.leftmargin = 0; vIDeoVIEw.setLayoutParams(params);
总结 以上是内存溢出为你收集整理的android-如何使VideoView全屏显示全部内容,希望文章能够帮你解决android-如何使VideoView全屏显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)