我有6个按钮。每个XML的XML如下。如何更改它们以使按钮文本居中并且它们的大小相同?
我认为设置大小会起作用吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/Button1"
android.layout_height="100px"
android.layout_width="60px"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="BUTTON1"/>
答案 0 :(得分:2)
对所有子高度和layout_weight =“1”使用fill_parent,希望它能正常工作
答案 1 :(得分:1)
你应该使用
android:layout_width="fill_parent"
而不是
android:layout_width="wrap_content"
按钮属性中的。 可以通过LinearLayout中的android:padding属性更改按钮宽度 例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="10px"
android:paddingRight="10px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/Button1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="BUTTON1"/>
答案 2 :(得分:1)
如果要设置按钮的文本中心,请使用: android:gravity =“center_vertical | center_horizontal”属性。
对于大小使用android:layout_height =“100px”和android:layout_width =“60px”属性。
这是按钮的完整xml布局:
<Button
android:id="@+id/button"
android:layout_height="100px"
android:layout_width="60px"
android:gravity="center_vertical|center_horizontal"
android:text="Your text!"/>