2015-10-05 71 views
0

屏幕所以我有這樣的代碼,這就是所謂onConfigurationChanged:Android的視頻幀不填充景觀

private void setVideoLayoutParams(){ 
    LinearLayout.LayoutParams params; 
    if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ 
     // this works as expected 
     showNavigationAndStatusBars(); 
     Display display = getWindowManager().getDefaultDisplay(); 
     Point size = new Point(); 
     display.getSize(size); 
     params = new LinearLayout.LayoutParams(size.x, size.x * 9/16); 
    }else{ 
     hideNavigationAndStatusBars(); 
     // this does not work properly 
     Display display = getWindowManager().getDefaultDisplay(); 
     Point size = new Point(); 
     display.getSize(size); 
     params = new LinearLayout.LayoutParams(size.x, size.y); 
    } 
    controller.setPauseButtonSize(); 
    Log.d(TAG, "video layout params set : " + params.width + "/" + params.height); 
    videoFrame.setLayoutParams(params); 
} 

private void hideNavigationAndStatusBars(){ 
    View decorView = getWindow().getDecorView(); 
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 

} 

private void showNavigationAndStatusBars(){ 
    View decorView = getWindow().getDecorView(); 
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
      | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; 
    decorView.setSystemUiVisibility(uiOptions); 
} 

當屏幕旋轉到景觀,導航和狀態欄消失。但是我的videoFrame不能填滿屏幕。

屏幕右側的一小部分保持空白,等於導航欄的高度。 屏幕底部等於通知欄高度的另一小部分保持空白。

當創建參數時,我的記錄器顯示1794/1080。當我觸摸屏幕時,我記錄了videoFrame的大小,並顯示1794/1009。我的猜測是它應該顯示,在這兩種情況下,1800/1080。

我在做什麼錯?

回答

0

將您的Videoview放入相對佈局中,並添加alignparentright,alignparentleft,alignparenttop和alignparentbottom「true」。這將是完美的。

+0

剛剛試了一下。我得到了相同的結果:( – kimv

+0

嘗試創建一個xml的橫向佈局,並按照我的說法做。它適用於我。 – Nivedh

+0

也沒有工作。它可能與我只刪除導航和狀態欄在橫向? – kimv

0

你的佈局是這樣吧?

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

並嘗試

  DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); 
     android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams(); 
     params.width = metrics.widthPixels; 
     params.height = metrics.heightPixels; 
     params.leftMargin = 0; 
     videoView.setLayoutParams(params); 
+0

它是match_parent而不是fill_parent,但除此之外,是 – kimv