title: Android – Am I Doing this Right?
body: <p>I am building an android app that requires a layout to be added programmatically.  This is the line that seems to be giving me a hard time:</p>
  
  <pre><code>RelativeLayout.LayoutParams rightScreenParams = new RelativeLayout.LayoutParams(
              (int) (screenWidth * 0.25), (int) (screenHeight * 0.94));
  </code></pre>
  
  <p>The variables screenWidth and screenHeight are the width and height of the screen in pixels.  The layout is supposed to be 25% of the width of the parent layout, and 94% of the height.  When I add the parameters to the layout and then add the layout, it takes up the entire screen instead of the dimensions I mentioned.</p>
  
  <p>So am I using this constructor correctly?  Any help is appreciated.  Thank you for your time.</p>
  
  <p>Edit:</p>
  
  <p>I get screenWidth and screenHeight in onCreate():</p>
  
  <pre><code>DisplayMetrics displayMetrics = new DisplayMetrics();
      WindowManager wm = (WindowManager) getApplicationContext()
              .getSystemService(Context.WINDOW_SERVICE);
      wm.getDefaultDisplay().getMetrics(displayMetrics);
      screenWidth = displayMetrics.widthPixels;
      screenHeight = displayMetrics.heightPixels
  </code></pre>
  
  <p>The variable screenHeight is returning as 1184 even though the actual height in pixels is 1280.  The variable screenWidth seems to be fine.  So how can I get an actual screen height in pixels?</p>