如果我在一个按钮中添加回车符,则会在顶部显示额外的“余量”(缺少更好的解释):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff992a2a">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp">
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Extend" />
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Accept
0:23"/>
</LinearLayout>
</RelativeLayout>
如何阻止额外的“保证金”出现?我尝试设置android:lines="2"
和/或android:singleline="false"
,但似乎没有任何帮助。
你需要在你的android:gravity="center"
中设置LinearLayout
示例代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff992a2a">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Extend" />
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Accept
0:23" />
</LinearLayout>
</RelativeLayout>
无需添加LinearLayout
。你可以只使用RelativeLayout
。试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff992a2a">
<Button
android:id="@+id/button_1"
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Extend" />
<Button
android:id="@+id/button_2"
android:layout_width="250dp"
android:layout_height="100dp"
android:layout_toRightOf="@id/button_1"
android:text="Accept
0:23" />
</RelativeLayout>