Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TextView offset downwards
    primarykey
    data
    text
    <p>I have an activity with two Buttons and a TextView in a LinearLayout. My TextView is offset downwards and the text doesn't fit inside the box. Can you explain what is happening? I think it is related to padding, and I've read several discussions about the perils of TextView padding, but that doesn't explain why the text is cut off at the bottom.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:background="#800080"&gt; &lt;Button android:text="This" android:background="@drawable/button_red" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;Button android:text="That" android:background="@drawable/button_green" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:text="Copious amounts of text that overflows onto several lines on a small screen, causing the TextView to dangle below the buttons. Why it does this I can't imagine. I only hope someone can help me with this." android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#533f93" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This code produces this display:</p> <p><img src="https://i.stack.imgur.com/qfTUE.png" alt="User interface"></p> <p>The purple is the LinearLayout, the blue is the TextView. As you can see, the TextView's top is below those of the buttons and its bottom is below the bottom of the LinearLayout. As I add text to the TextView, the LinearLayout increases its height appropriately, but because the TextView is offset, I always lose the bottom of the last line.</p> <p>I ran Hierarchy Viewer and it gave me this wireframe:</p> <p><img src="https://i.stack.imgur.com/5G9DU.png" alt="Wireframe image from Hierarchy Viewer"></p> <p>Which shows the vertical offset at the top, but misses the bottom of the TextView. The same wireframe with the LinearLayout selected looks like this:</p> <p><img src="https://i.stack.imgur.com/HMyKC.png" alt="Wireframe image from Hierarchy Viewer - LinearLayout selected"></p> <p>According to Hierarchy Viewer, the top of the buttons is at 0, but the top of the TextView is at 7. I've tried various fixes, mostly culled from this site:</p> <pre><code> android:paddingTop="0dp" android:background="@null" android:includeFontPadding="false" </code></pre> <p>None of these fixed my issue.</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.
    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