Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Layout height is bigger than expected
    text
    copied!<p>Can somebody please explain why layout is much bigger than button vertically. Im using WRAP_CONTENT for the layout height. Also Second button just disappeared. </p> <p>Layout:</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="wrap_content" android:layout_height="wrap_content" android:background="#f00" &gt; &lt;Button android:id="@+id/Button01" android:text="Button One big button" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;Button android:id="@+id/Button02" android:text="Button Two" android:layout_toLeftOf="@id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;/RelativeLayout&gt; </code></pre> <p><img src="https://i.stack.imgur.com/9uajs.jpg" alt="enter image description here"></p> <p>I can see that it is because of using layout_toLeftOf tag with a anchor view (Button 01) whose position width wise is not precisely defined. Im looking for more insights here. Can anybody chip in??</p> <p>Thanks in advance.</p> <p>EDIT:</p> <ul> <li>Why does Button 2 disappear : Quiroga has put down a good answer below </li> <li><p>Why Layout height increase : Experimets reveal that its because of Button02 width!! Platform has pushed the button 02 to the invsible space on the left of the layout but squeezed it to a single char width. For exmaple if the change the text of the buton 02 as follows</p> <p>android:text="Btn 2"</p> <p>Then output changes to (height of layout reduced) <img src="https://i.stack.imgur.com/0FBIa.jpg" alt="enter image description here"></p></li> </ul> <p>So the bottom line -- Make sure to use right alignment parameters. Else some of your views might disappear and worse layout appearance can be hugely different from what you expect! </p>
 

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