Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want the display dimensions in pixels you can use <a href="http://developer.android.com/reference/android/view/Display.html#getSize%28android.graphics.Point%29" rel="noreferrer"><code>getSize</code></a>:</p> <pre><code>Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; </code></pre> <p>If you're not in an <code>Activity</code> you can get the default <code>Display</code> via <code>WINDOW_SERVICE</code>:</p> <pre><code>WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); </code></pre> <p>Before <code>getSize</code> was introduced (in API level 13), you could use the <code>getWidth</code> and <code>getHeight</code> methods that are now deprecated:</p> <pre><code>Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); // deprecated int height = display.getHeight(); // deprecated </code></pre> <p>For the use case you're describing however, a margin/padding in the layout seems more appropriate.</p> <p>Another way is: <a href="http://developer.android.com/reference/android/util/DisplayMetrics.html" rel="noreferrer">DisplayMetrics</a></p> <blockquote> <p>A structure describing general information about a display, such as its size, density, and font scaling. To access the DisplayMetrics members, initialize an object like this:</p> </blockquote> <pre><code>DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); </code></pre> <p>We can use <code>widthPixels</code> to get information for: </p> <blockquote> <p>"The absolute width of the display in pixels."</p> </blockquote> <p><strong>Example:</strong></p> <pre><code>Log.d("ApplicationTagName", "Display width in px is " + metrics.widthPixels); </code></pre>
 

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