Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Forget on my previously answer not working on all versions. The right approach is to find out navigation bar height and add bottom margin -navigationBarHeight. This is full working example work on all 4.1+ versions: </p> <pre><code>public static int getNavigationBarHeight(Context context) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId &gt; 0) { return resources.getDimensionPixelSize(resourceId); } return 0; } @SuppressLint("NewApi") private int getRealScreenSize(boolean returnWidth) { final DisplayMetrics metrics = new DisplayMetrics(); Display display = getActivity().getWindowManager().getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; //Not real dimensions display.getMetrics(metrics); int width = metrics.heightPixels; int height = metrics.widthPixels; try { // For JellyBeans and onward if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(metrics); //Real dimensions width = metrics.heightPixels; height = metrics.widthPixels; } else { mGetRawH = Display.class.getMethod("getRawHeight"); mGetRawW = Display.class.getMethod("getRawWidth"); try { width = (Integer) mGetRawW.invoke(display); height = (Integer) mGetRawH.invoke(display); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (NoSuchMethodException e3) { e3.printStackTrace(); } if (returnWidth) { return width; } else { return height; } } </code></pre> <p>Following example code need to put somewhere after surface was created:</p> <pre><code>RelativeLayout.LayoutParams lp = (LayoutParams) surfaceView.getLayoutParams(); int screenHeight = getRealScreenSize(false); int screenWidth = getRealScreenSize(true); int navigationBarHeight = getNavigationBarHeight(getActivity()); lp.height = (int) (screenWidth / (16d / 9d)); lp.width = screenWidth; int k = (lp.height - screenHeight) / 2; lp.setMargins(0, -k, 0, (-k) - navigationBarHeight); surfaceView.setLayoutParams(lp); </code></pre> <p>Note that surface view must have parent RelativeLayout.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload