【发布时间】:2012-11-14 02:58:09
【问题描述】:
我可能是个白痴,但似乎将Button 添加到水平LinearLayout 会破坏layout_gravity="top"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="top"
android:text="TextView"
android:background="#f00" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_weight="0"
android:text="Button" />
</LinearLayout>
这看起来像这样(在布局编辑器中):
请注意,文本视图位于中心,而不是顶部!如果*我所做的只是删除<button>,那么它看起来像这样:
看,现在它应该在顶部。我将使用的解决方法是使用layout_gravity="start",这确实会导致正确的行为:
但无论如何,发生了什么事?另见this related question。这实际上可能是同一个问题;我不确定。反正那里没有真正的答案。
【问题讨论】:
标签: android android-layout android-linearlayout layout-gravity