0

这是一个按钮的代码。我想把加号放在中间(垂直和水平)。但是,这是行不通的。

<Button
        android:id="@+id/zoomNineteen"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/zoomTwenty"
        android:gravity="center"
        android:textSize="20dip"
        android:textStyle= "bold"
        android:text="+" />
4

1 回答 1

1

Adding the attribute android:gravity="center" will center the text.

The problem you may be having is that most Button backgrounds in Android include a certain amount of padding as part of the image - this means it won't look centered.

In order for it to look centered you're going to need to also include:

android:background="@drawable/custom_selector"

pointing to either a custom image or more usefully a selector containing multiple images which don't include extra padding / margins.

于 2013-04-03T15:56:39.090 回答