如果我在一个按钮中添加回车符,则会在顶部显示额外的“余量”(缺少更好的解释):
<?xml version =“1.0”encoding =“utf-8”?>< RelativeLayout的 的xmlns:…
无需添加 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>
你需要设置 的 android:gravity="center" 强> 在你的 LinearLayout
android:gravity="center"
的 示例代码 强>
<?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>