我有一个包含两个按钮和一个文本视图的线性布局。我的文本视图向下偏移,文本无法适应框内。你能解释一下这是怎么回事吗?我认为这与填充有关,我已经阅读了几篇关于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>
这段代码生成了这个显示效果:
![用户界面](https://istack.dev59.com/qfTUE.webp)
我运行了Hierarchy Viewer并得到了这个线框图:
![Hierarchy Viewer中的线框图像](https://istack.dev59.com/5G9DU.webp)
![从Hierarchy Viewer中的线框图像 - 选择LinearLayout](https://istack.dev59.com/HMyKC.webp)
android:paddingTop="0dp"
android:background="@null"
android:includeFontPadding="false"
这些方法都没有解决我的问题。
LinearLayout
中的每个后续小部件都与其前面的小部件基线对齐。在我们的例子中,TextView
的 第一行 与Button
的文本基线对齐。我同意,这不是直观的行为,但它就是这样。 - StenaviN