Android Question Font size

Pete_S

Member
Licensed User
I have a simple multiple choice app for learning Chinese or Thai language. It loads words and definitions from an Excel file. Some definitions are long in length, some are short in length.

Is there a clever way to set the font width based on the width of the device?
 

Attachments

  • font bad 2.PNG
    font bad 2.PNG
    409.5 KB · Views: 172
  • font bad.png
    font bad.png
    368.7 KB · Views: 185

Pete_S

Member
Licensed User
Right now (if you look at the screenshots from my first post) I use 1 Label and 4 Buttons. Are you saying to add/embed these Views INSIDE a xCustomListView? How will it prevent the text cutoffs that I'm currently experiencing? Or do you suggesting I REPLACE these Views with a xCustomListView?

I will try to do it.

Is xCustomListView.zip and CustomListView.bas from https://www.b4x.com/android/forum/t...listview-cross-platform-customlistview.84501/ the best examples for me to look at?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Pete_S

Member
Licensed User

Attachments

  • LabelAndButtonTextFitting.zip
    150.9 KB · Views: 119
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version with an improved version of the first link.
The problem with Buttons is that they have a padding, which means that the text area is smaller than the view dimensions.
The StringUtils.MeasureMultilineTextHeight method doesn't take into account the padding.
 

Attachments

  • LabelAndButtonTextFitting1.zip
    7.9 KB · Views: 114
Upvote 0

Pete_S

Member
Licensed User
Thanks Klaus
Most of the text I use adjusts correctly thanks to your code but there are some exceptions. To see some of these exceptions look at the attached screenshot. As you can see the Label1 and Button2 lines are problematic.

B4X:
SetTextSize(Label1, "星期 (xing1 qi1)")
SetTextSize(Button1, txt)
SetTextSize(Button2, "vegetables; greens; (non-staple) food")
SetTextSize(Button3, "小 (xiao3)")
SetTextSize(Button4, "hi")
 

Attachments

  • ss.jpg
    ss.jpg
    42.3 KB · Views: 142
Upvote 0

klaus

Expert
Licensed User
Longtime User
Set the limit to
Private limit = 0.001 As Float
instaed of
Private limit = 0.5 As Float
It seems that the text is at the limit betwwen one line and two lines:
On my device:
TextSize = 19.166 one line
TextSize = 19.167 two lines
 
Upvote 0
Top