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.