0

I am using this code and the view does not fit the whole screen of the device.

    DisplayMetrics metricsLandscape = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metricsLandscape);              
    relVideoHolder.setLayoutParams(new RelativeLayout.LayoutParams(metricsLandscape.widthPixels, metricsLandscape.heightPixels));
    videoView.setLayoutParams(new RelativeLayout.LayoutParams(metricsLandscape.widthPixels, metricsLandscape.heightPixels));
    Log.e("DIMENSIONS", "WIDTH by HEIGHT"+ metricsLandscape.widthPixels+"by"+metricsLandscape.heightPixels);
    Log.e("VIDEOHOLDER dimension WxH", ""+relVideoHolder.getWidth()+"x"+relVideoHolder.getHeight());
    Log.e("VIDEOVIEW dimension WxH", ""+videoView.getWidth()+"x"+videoView.getHeight());

I find this weird because the result of the Logcat is here;

02-14 17:17:25.881: E/DIMENSIONS(6314): WIDTH by HEIGHT 1196by720
02-14 17:17:25.881: E/VIDEOHOLDER dimension WxH(6314): 720x410
02-14 17:17:25.881: E/VIDEOVIEW dimension WxH(6314): 720x403

I wonder why they have different values. Sometimes, the view covers all the screen, but most of the time, it does not fit the full screen. Please help me. By the way, I call these codes onConfigurationChanged when Landscape orientation. Thank you.

kads
  • 112
  • 1
  • 10

2 Answers2

2
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

If you're not in an Activity you can get the default Display via WINDOW_SERVICE:

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
  • Use of getWidth and getHeight has been deprecated. http://developer.android.com/reference/android/view/Display.html#getSize(android.graphics.Point) – Nayan Rath Feb 14 '14 at 09:06
0

I just add getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); to my code and it works like a charm.

kads
  • 112
  • 1
  • 10