Android Question [solved]Why button text not center_vertical?

Maodge

Member
Licensed User
Hi,
in my project , i set button text property as Attached File designer setting.png
"center_horizontal,center_vertical"
and script
B4X:
btnMusicTuneMid.Width=15%x
btnMusicTuneMid.Height=40dip
btnMusicTuneMid.Top=355dip
btnMusicTuneMid.Left=67%x
btnMusicTuneMid.TextSize=22

but part of the text is not displayed,and the text is not center_vertical.
there some place at the top of button.
And how to solve this problem ?
Thanks
 

Attachments

  • 20180525170410.jpg
    20180525170410.jpg
    241.3 KB · Views: 305
  • designer setting.png
    designer setting.png
    146.5 KB · Views: 284

Maodge

Member
Licensed User
What padding values do you have?
The text size is probably too big for the button height.
device details: 720 X 1280, scale = 2 (320 dpi)

And could you give some suggestions about how to determine the size of the text?
Thanks a lot
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It is possible to calculate the text height with the MeasureMultilineTextHeight method from the StringUtils library.
Then you need to know the Padding of the view, which are are extra spaces arround the text.
Additionnally, buttons with the default background are smaller than the external dimensions.

Attached a small test project showing the differences.

upload_2018-5-25_13-47-51.png


The upper button is a 'standard' button with a height of 40dip and a text size of 22, your case.
The second button has a Padding of 0, 0, 0, 0.
The third button has a 'standard' color background, with the full dimensions.
 

Attachments

  • ButtonTextSize.zip
    9.2 KB · Views: 243
Upvote 0
Top