some days after the product launch I received some screenshoots from google with my app on different devices.
One of them looks like this...
Nokia 1 Android 8.1
How can I ensure, that the "S" fits on each device?
Does anybody know, how these screenshots are made? I have a lot of them with empty "instrument labels" (see picture above all entries in the middle). Are they Auto-generated? This state is only possible in the moment of loading the next song. One second later there will be entries. But now I'm not sure if this screenshot shows coincidentally this moment or whether it shows a real bug.
Based on the large title, the user has increased the default text size. There is no simple solution for this case. You can change it in the device settings.
Now I visited the Developer Console and there I found a "Pre-Launch report", where Google suggests me not to use element heights smaller than 48dip. In the screen above I really used 45dip. I will change the minimun height of elements to 48dip and see, what happens. Maybe this is also enough for this problem...
But... can I calculate the hight of string using a certain font and compare it with the size of the element? Something like "TextWidth" or "TextHeight"? It would help to know a way to find the "biggest avaiable textsize" inside a element.
Yes.
As Brian Dean already suggested with StringUtils.MeasureMultilineTextHeight.
But you need to also take into account the padding.
The code below calculates the max text size for a given TextView (Label), includes Labels, EditText and Button views.
Depends on the StringUtils and JavaObject libraries.
You can calculate the TextSize once and set the value to all other Buttons.
B4X:
Private Sub GetMaxTextSize(lbl As Label) As Float
Private jo As JavaObject
Private su As StringUtils
Private AvailableHeight, TextHeight, PaddingTop, PaddingBottom As Int
jo = lbl
PaddingTop = jo.RunMethod("getPaddingTop", Null)
PaddingBottom = jo.RunMethod("getPaddingBottom", Null)
TextHeight = su.MeasureMultilineTextHeight(lbl, "M")
AvailableHeight = lbl.Height - PaddingTop - PaddingBottom
Return lbl.TextSize / TextHeight * AvailableHeight
End Sub
Attached my small test program.
It works also if the user sets bigger text sizes.