Note that there are some explanatory texts on larger screens.

plurals
  1. POSet position / size of UI element as percentage of screen size
    primarykey
    data
    text
    <p>I'm trying to work out if it's possible to use percentage positions/sizes when creating a layout. What I want is something like this...</p> <pre><code>^ | | | 68% | | v Gallery (height equivalent of 16% total screen size) ^ | 16% v </code></pre> <p>I'm testing on a device which in landscape has a display of 800x480 actual pixels and I'm currently forcing it with the following...</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="80px" android:layout_marginTop ="320px" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Obviously I don't want to hard-code fixed <code>px</code> units but I can't use <code>68%</code> or <code>0.68</code> for <code>layout_marginTop</code> (for example). I've looked at <code>dp</code> units but I'm not sure if I can do it that way either.</p> <p>I have to admit UI design is a weak point of mine so any advice would be gratefully received.</p> <p><strong>EDIT:</strong> For future reference if anyone is looking for a similar answer, following Alan Moore's suggestion I have the following working exactly how I want it...</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="@drawable/bground" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.68" android:background="@android:color/transparent" /&gt; &lt;Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.16" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0.16" android:background="@android:color/transparent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>I managed to find some other examples of using <code>layout_weight</code> and decided to set the <code>TextView</code> heights to <code>0dp</code> and also used floats for the weights. Working great. :)</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.
 

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