横向模式下视频视图不是全屏

时间:2012-06-14 05:35:57

标签: android xml landscape

我正在使用使用xml设计的视频视图。此视频在纵向模式下全屏显示,但当它转为横向模式时,它会保持对齐状态,宽度和高度都会被包裹而不是全屏。

我提到了这些,但仍然没有解决方案。

Fullscreen VideoView isn't Centered

Android-Video View in Fullscreen

任何人都知道答案吗?

更新:这是我的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/youtubewebView"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true" android:layout_gravity="fill" />

</RelativeLayout>

更新2:

public class VideoStreamingActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
    String videoUrl = "http://www.pocketjourney.com/downloads/pj/video/famous.3gp";
    try {
    Uri uri = Uri.parse(videoUrl);
    videoView.setVideoURI(uri);
    videoView.setMediaController(new MediaController(this));
    videoView.requestFocus();
    //videoView.start();
    videoView.setOnErrorListener(new OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    }catch (Exception e) {
        e.printStackTrace();
    }

    videoView.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {
            videoView.start();
        }
    });

}

@Override
protected void onPause() {
    Toast.makeText(getApplicationContext(), "pause", Toast.LENGTH_SHORT).show();
    super.onPause();
}

@Override
protected void onRestart() {
    Toast.makeText(getApplicationContext(), "restart", Toast.LENGTH_SHORT).show();
    super.onRestart();
}

@Override
protected void onResume() {
    Toast.makeText(getApplicationContext(), "resume", Toast.LENGTH_SHORT).show();
    super.onResume();
}

}

1 个答案:

答案 0 :(得分:33)

你确定它没有填满屏幕。这对我来说可以。这是xml文件,

<强> main.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"
    android:orientation="vertical" >

    <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"
        />
</RelativeLayout>

<强>的onCreate()

VideoView video=null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    video=(VideoView)findViewById(R.id.video);
    video.setVideoURI(Uri.parse("http://www.pocketjourney.com/downloads/pj/video/famous.3gp"));
    video.start();
}

纵向模式的ScreenShot

enter image description here

横向模式的屏幕截图

enter image description here