Android - Button text center gravity not working -


i have xml layout in app (example of 1 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 start app @ android 4.3, text of buttons isn´t in center of button. @ screenshot (in red rectangle):

enter image description here

where can problem?

edit:

whole layout

when specify:

    android:layout_alignbottom="@+id/chcksprotka"     android:layout_alignright="@+id/chcksprotka"     android:layout_aligntop="@+id/chcksprotka"   

it make bottom/right/top edge of button match bottom edge of given anchor view id & accommodates bottom/right/top margin, but while doing that, android_gravity not take resultant height/width consideration.

so gravity of text center according wrap_content layout_height , layout_width.

you can verify setting values layout_height , layout_width (eg. 200dp , 100dp try with) , text gravity center height , width.

to confirm same, can use container linearlayout 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 gravity of linearlayout center , center button within or shown above, use layout_gravity button center in parent linearlayout.
work solution when 4 buttons, there might better options if restructure xml , avoid kind of nesting.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -