2

我正在尝试将在全屏活动中播放的视频居中,但是我在任何布局中放置的任何参数似乎都不起作用

这是我的清单:

<activity
    android:name=".VideoActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>

我的 video_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

  <VideoView 
    android:id="@+id/videoView" 
    android:gravity="center"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/>

</LinearLayout>

以及您需要时的活动

public class VideoActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_layout);

    VideoView videoHolder = new VideoView(this);
    setContentView(videoHolder);
    Uri video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.video);
    videoHolder.setVideoURI(video);
    videoHolder.start();

    videoHolder.setOnCompletionListener(new OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            jump();
        }
    });
}   

private void jump() {
    if(isFinishing())
      return;
     finish();
     pd.dismiss();
    }
 }

我试过 FrameLayou、RelativeLayout、LinearLayout

重心居中,layout_gravity 居中,它会一直显示在纵向窗口的顶部和横向的左下角

我会放一张照片,但我缺乏声誉提前谢谢

4

1 回答 1

5

这对我有用:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center">
    </VideoView>

</FrameLayout>
于 2013-08-06T19:37:32.017 回答