【发布时间】:2014-11-23 14:32:59
【问题描述】:
我想以正常尺寸纵向显示我的视频,并以全尺寸横向显示我的视频。因此,当用户开始以纵向观看并切换到横向(旋转设备)时,它会进入全屏状态;反之亦然,它会恢复到原始大小。我检查了互联网,但找不到一个很好的例子。我的代码如下。
VideoActivity.java:
公共类 VideoActivity 扩展 Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_video);
Bundle bund = getIntent().getExtras();
String s = bund.getString("LINK");
VideoView videoView = (VideoView) findViewById(R.id.videoView);
MediaController controller = new MediaController(this);
videoView.setVideoPath(s);
videoView.setMediaController(controller);
videoView.start();
}
}
activity_video.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}"
android:background="#000000"
>
<VideoView
android:id="@+id/videoView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>
基本上。当用户开始播放视频时,它可以是原始大小(如果是纵向模式),但每当他转动手机时,我希望它自动全屏显示。当转回纵向时,又是原来的大小。
谢谢。
【问题讨论】:
标签: android fullscreen android-videoview landscape