I have this XML layout in my App (example of one button):

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollViewMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff0e8" >

    ///some views       

    <Button
        android:id="@+id/btnVysledkySportka"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/chckSprotka"
        android:layout_alignRight="@+id/chckSprotka"
        android:layout_alignTop="@+id/chckSprotka"
        android:layout_margin="3dp"
        android:layout_toRightOf="@+id/textView3"
        android:background="#ffe118"
        android:gravity="center"
        android:onClick="vysledkySportka"
        android:text="Archiv výsledků"
        android:textStyle="bold" />

 ///some views    
</RelativeLayout>

</ScrollView>

But when I start my app at Android 4.3, the text of buttons isn´t in center of button. Look at the screenshot (in red rectangle):

enter image description here

Where can be problem?

EDIT:

Whole layout

有帮助吗?

解决方案

When you specify:

    android:layout_alignBottom="@+id/chckSprotka"
    android:layout_alignRight="@+id/chckSprotka"
    android:layout_alignTop="@+id/chckSprotka"  

It does make the bottom/right/top edge of your button match the bottom edge of the given anchor view ID & accommodates bottom/right/top margin, but while doing that, the android_gravity does not take the resultant height/width into consideration.

So the gravity of the text is center according to wrap_content for layout_height and layout_width.

You can verify that by setting values for layout_height and layout_width (Eg. 200dp and 100dp to try with) and you will get the text with gravity center but for that height and width.

To confirm the same, what you can do is use a container LinearLayout for your Button like:

 <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/chckStastnych"
            android:layout_alignRight="@+id/chckStastnych"
            android:layout_alignTop="@+id/chckStastnych"
            android:layout_margin="3dp"
            android:layout_toRightOf="@+id/textView3"
            android:background="#ffe118" >

            <Button
                android:id="@+id/btnVysledkyStastnych"
                android:layout_gravity="center"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ffe118"
                android:gravity="center"
                android:onClick="vysledkyStastnych"
                android:text="Archiv výsledků"
                android:textStyle="bold" />
        </LinearLayout>  

Set the gravity of LinearLayout as center and then center the Button within or as shown above, use layout_gravity for the button to center it in parent LinearLayout.
This will work as a solution when you do that for all 4 buttons, however there might be better options if you restructure your xml and avoid this kind of nesting.

其他提示

Try This:

<Button
            android:id="@+id/btnVysledkySportka"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/chckSprotka"
            android:layout_alignRight="@+id/chckSprotka"
            android:layout_alignTop="@+id/chckSprotka"
            android:layout_margin="3dp"
            android:layout_toRightOf="@+id/textView3"
            android:background="#ffe118"
            android:gravity="center_vertical"
            android:onClick="vysledkySportka"
            android:text="Archiv výsledků"
            android:textStyle="bold" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top