Android-全屏视频查看
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3776254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android-Video View in Fullscreen
提问by bharathi
I am trying to make this VideoView to appear in full screen mode :
我试图让这个 VideoView 以全屏模式显示:
public class ViewVideo extends Activity {
private String filename;
private static final int INSERT_ID = Menu.FIRST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.gc();
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("videofilename");
VideoView vv = new VideoView(getApplicationContext());
setContentView(vv);
vv.setVideoPath(filename);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, 0,"FullScreen");
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case INSERT_ID:
createNote();
}
return true;
}
private void createNote() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
The video is playing from sdcard. Only thing is when I click on the full-screen menu button, the application "stops unexpectedly".
视频正在从 sdcard 播放。唯一的问题是当我点击全屏菜单按钮时,应用程序“意外停止”。
Please help me out, how to get the video to run in full screen? Thanks in advance.
请帮帮我,如何让视频全屏运行?提前致谢。
回答by Javanator
No need of code to play video in full screen mode
无需代码即可在全屏模式下播放视频
Apply the following layout format over the xml containing the videoview it will for sure will play the video in full screen mode. as it is running mine :) Hope it helps
在包含视频视图的 xml 上应用以下布局格式,它肯定会以全屏模式播放视频。因为它正在运行我的 :) 希望它有帮助
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
回答by Praveen
when you click an menu item. you have to start a New Activity. for that Activity you have to set the theme attribute in the Manifest. set this value that is
当您单击菜单项时。你必须开始一个新的活动。对于该活动,您必须在清单中设置主题属性。设置这个值是
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
thats it.
就是这样。
回答by samreen
Perhaps it's because you have to add following code:
也许是因为您必须添加以下代码:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
before setContentView(your_content_view)
to get rid of app title bar. I know its a very late reply but somebody might find it useful.
之前setContentView(your_content_view)
摆脱应用程序标题栏。我知道这是一个很晚的回复,但有人可能会觉得它很有用。
回答by Michael
Due to my experienced, you can only use Relative-Layout View for you video to be stretch on portrait and landscape. Linear-layout view can only stretch video on Landscape, you can try the two view without writing any code and prove my theory
由于我的经验,您只能使用相对布局视图让您的视频在纵向和横向上拉伸。线性布局视图只能在横向上拉伸视频,您可以不写任何代码来尝试这两种视图并证明我的理论
回答by SAWAUNG
Okey, Let's try like this, this was suitable for my full screen.
好吧,让我们试试这个,这适合我的全屏。
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
回答by THZ
Portrait layout
纵向布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@android:color/black">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
Landscape layout
景观布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<VideoView
android:id="@+id/video_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</FrameLayout>