2012-05-09 66 views
4

我使用此XML佈局在我的活動中顯示全屏VideoView。該視頻是全屏,但它不居中。在橫向模式下,它保持在屏幕的左側,並在屏幕的右側留下一些空白區域。全屏VideoView不居中

我怎樣才能讓我的VideoView放置在屏幕的中心?

<?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> 
+0

嘗試[該解決方案(http://stackoverflow.com/questions/8293909/surfaceview-height-width-gets-ignored/20798009#20798009)希望工程妳。 使佈局作爲andro說,但與填充父母,而不是包裝內容。 –

回答

3

試試這個:

<?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_height="fill_parent" 
      android:layout_centerInParent="true"> 
    </VideoView> 
</RelativeLayout> 

希望這有助於。

+0

它不適用於肖像。我看到屏幕頂部的視頻。 – bashan

10

試試這個佈局,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:gravity="center"> 



     <VideoView android:id="@+id/videoview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"/> 

</RelativeLayout> 
+1

「RelativeLayout」沒有方向,但這對我有用!它應該被接受爲正確的答案 – Guillaume

+0

感謝您的解決方案! – dhun

+0

它不適用於肖像。我看到視頻與屏幕頂部對齊。 – bashan

0

你需要有兩個不同的佈局。一個用於肖像和一個用於景觀。創建兩個具有相同名稱的xml文件,並將其放置到文件夾「layout-land」的橫向和「佈局端口」的肖像。

,在這裏你可以看看如何處理方向變化。

這可以使視頻全屏顯示的佈局。

-1

如果您VideoView不能RelativeLayout的中心,你可以嘗試把它變成一個FrameLayout裏是這樣的:

<FrameLayout 
    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> 

然後把這個到RelativeLayout的。

+0

它不適用於肖像。我仍然看到視頻與屏幕頂部對齊。 – bashan