【发布时间】:2016-07-05 02:23:34
【问题描述】:
所以,我尝试使用线性布局来容纳三个不同的按钮,每个按钮应占一行宽度的 33%。此线性布局将位于我的相对布局中的所有其他内容下方,该布局包含此活动上的所有其他小部件。不幸的是,当我将第三个按钮添加到布局中时,其他两个按钮的底部有一个白条,第三个按钮(在本例中为主页按钮)的位置高于其他按钮。
有人可以解释这种行为以及如何纠正它吗?谢谢。
这是线性布局的 XML 文件,我已经删除了其他小部件的所有文本。如果这有帮助,我也可以发布它。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<Button
android:layout_width="0dp"
android:layout_weight=".33"
android:layout_height="wrap_content"
android:text="@string/adfazsdfasdfadfsagjlfkdlgjklfsadgfjgps"
android:onClick="resetDates"
android:background="@drawable/sumbitstyleing"
android:id="@+id/resetDatesButton" />
<Button
android:layout_width="0dp"
android:layout_weight=".33"
android:layout_height="wrap_content"
android:text="@string/home"
android:onClick="home"
android:id="@+id/homeButtonSearch"
android:background="@drawable/generalbutton" />
<Button
android:layout_weight=".33"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/submitchanges"
android:onClick="submitChanges"
android:background="@drawable/sumbitstyleing"
android:id="@+id/submitchanges" />
</LinearLayout>
第一张图没有第三个按钮,第二张图有第三个按钮。
【问题讨论】:
-
不要使用 alignParentEnd 和 alignParentRight。首先,这两者在 LTR 语言中会发生冲突。其次,由于您在宽度上 match_parent,您将自动对齐到父级的两侧。 (alignParentBottom 很好,不会冲突)。
-
将
android:baselineAligned="false"添加到LinearLayout以使Buttons 排队。我不确定白线是什么。某种渲染故障?这是在模拟器中,还是在布局设计师中?
标签: android button android-linearlayout