LinearLayoutに2つのボタンとTextViewを持つアクティビティがあります。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>
このコードは次の表示を生成します:
紫はLinearLayout、青はTextViewです。ご覧のとおり、TextViewの上部はボタンの上部の下にあり、下部はLinearLayoutの下部の下にあります。TextViewにテキストを追加すると、LinearLayoutの高さが適切に増加しますが、TextViewがオフセットされているため、常に最後の行の下部が失われます。
Hierarchy Viewerを実行すると、次のワイヤーフレームが表示されます。
これは上部に垂直オフセットを示していますが、TextViewの下部を見逃しています。LinearLayoutが選択された同じワイヤーフレームは次のようになります。
Hierarchy Viewerによると、ボタンの上部は0ですが、TextViewの上部は7です。私はさまざまな修正を試しましたが、ほとんどがこのサイトから抜粋したものです。
android:paddingTop="0dp"
android:background="@null"
android:includeFontPadding="false"
これらのどれも私の問題を修正しませんでした。