Recently I posted a similar question, and from the responses, I came up with what I thought would be a solution to match text size to label & item heights irrespective of device. It worked great on the emulator (320x480 scale=1 160dpi), but on my Galaxy S (480x800 233ppi) the bottom portion of text is cut off.
My solution was to use TextSize to set Label.Height to set ItemHeight as given below. Can anyone help me to get this right so that for any given textsize, the text will fit into the listview item with the amount of padding specified?
My solution was to use TextSize to set Label.Height to set ItemHeight as given below. Can anyone help me to get this right so that for any given textsize, the text will fit into the listview item with the amount of padding specified?
B4X:
Sub SetLVHeights4TextSize(LV As ListView, TwoLine As Boolean, Text1Size As Float, Text2Size As Float, Padding As Float)
If TwoLine = True Then
LV.TwoLinesLayout.Label.Top = 0
LV.TwoLinesLayout.Label.TextSize = Text1Size
LV.TwoLinesLayout.Label.Height = Text1Size + (2 * Padding)
LV.TwoLinesLayout.SecondLabel.Top = LV.TwoLinesLayout.Label.Height
LV.TwoLinesLayout.SecondLabel.TextSize = Text2Size
LV.TwoLinesLayout.SecondLabel.Height = Text2Size + (2 * Padding)
LV.TwoLinesLayout.ItemHeight = LV.TwoLinesLayout.Label.Height + LV.TwoLinesLayout.SecondLabel.Height
LV.TwoLinesLayout.Label.Gravity = Gravity.CENTER_VERTICAL
LV.TwoLinesLayout.SecondLabel.Gravity = Gravity.CENTER_VERTICAL
Else
LV.SingleLineLayout.Label.Top = 0
LV.SingleLineLayout.Label.TextSize = Text1Size
LV.SingleLineLayout.Label.Height = Text1Size + (2 * Padding)
LV.SingleLineLayout.ItemHeight = LV.SingleLineLayout.Label.Height
LV.SingleLineLayout.Label.Gravity = Gravity.CENTER_VERTICAL
End If
End Sub