Android TextView смещается вниз

У меня есть активность с двумя кнопками и TextView в LinearLayout. Мой TextView смещен вниз, и текст не помещается внутри поля. Можете ли вы объяснить, что происходит? Я думаю, что это связано с заполнением, и я читал несколько дискуссий об опасностях заполнения TextView, но это не объясняет, почему текст обрезается внизу.

<?xml version="1.0" encoding="utf-8"?>
<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">

    <Button
        android:text="This"
        android:background="@drawable/button_red" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <Button
        android:text="That"
        android:background="@drawable/button_green" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <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"
    />
</LinearLayout>

Этот код выводит на экран следующее:

User interface

Фиолетовый — LinearLayout, синий — TextView. Как видите, верхняя часть TextView находится ниже кнопок, а нижняя часть — ниже нижней части LinearLayout. Когда я добавляю текст в TextView, LinearLayout соответствующим образом увеличивает его высоту, но поскольку TextView смещается, я всегда теряю нижнюю часть последней строки.

Я запустил Hierarchy Viewer, и он дал мне вот такой каркас:

Wireframe image from Hierarchy Viewer

Который показывает смещение по вертикали вверху, но пропускает нижнюю часть TextView. Тот же каркас с выбранным LinearLayout выглядит следующим образом:

Wireframe image from Hierarchy Viewer - LinearLayout selected

Согласно Hierarchy Viewer, верхняя часть кнопок находится на 0, а верхняя часть TextView — на 7. Я пробовал различные исправления, в основном взятые с этого сайта. :

    android:paddingTop="0dp"
    android:background="@null"
    android:includeFontPadding="false"

Ни один из них не решил мою проблему.

5
задан TomDestry 16 May 2012 в 12:02
поделиться