Android Question ListView Size

alexanderjames

Member
Licensed User
Longtime User
Hi All

I'm using a ListView simply to display information to the user, so it wont be used for anything fancy. The problem I'm having is that it looks great on a 10" tablet but the smaller the phone the bigger the text and lines become. So on a 10" tablet I might have 10 rows but on a 5" screen I'll only have 3 big rows with big text. I've had a look at the properties of the ListView and nowhere can you specify row height or text sizes. Is there a way to get the listview to resize along with the rest of the views ? or is there a better view that I can use just to display a couple of lines of information ?

Any advice in this regard would be greatly appreciated.

Many thanks in advance.
AJ
 

eps

Expert
Licensed User
Longtime User
How are you defining the size of the elements? Are you using DIP or X%?

You can set the item height and text size for ListView. You need to set the ListView.Label.Height and so on.. http://www.b4x.com/android/help/views.html#label

You might also need to include a factor to ensure that things are bigger on a Tablet for instance. There's quite a bit of code around, on the Forum that detects if a device is a Tablet or not. The best way would seem to detect Telephony being available and then discounting devices which are known to be tablets, but have telephony - you'll have to search for that.

HTH
 
Upvote 0

alexanderjames

Member
Licensed User
Longtime User
Hi eps

Thank you for your reply, the listview doesn't have those properties for me to adjust and this is what's really puzzling me. I have declared the list view as follows in the designer.

Dim lstMessage As ListView

I have all my other views adjusting using designer scripts, except for the list view as it has no settings. I'll give your link suggestion a read, maybe I missed something.

Thanks
AJ.
 
Upvote 0

alexanderjames

Member
Licensed User
Longtime User
Reading the link I can see that none of the functions I need are available in the designer script section, this is strange as every other view you can set all the properties within the designer scripts and these will resize accordingly.

Thanks.
AJ
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Did you set any of these properties in the code ?
ListView1.SingleLineLayout.xxx
ListView1.TwoLinesLayout.xxx
ListView1.TwoLinesAndBitmap.xxx
If yes you need to use a scaling for those.
B4X:
scale = 1 + rate *  ((100%x + 100%y) / (320dip + 430dip) - 1)
ListView1.SingleLineLayout.ItemHeight = 40 * scale
ListView1.SingleLineLayout.Label.TextSize = 16 * scale
' etc
Where rate is the value of the ScaleRate you used in the DesignerScripts and 40 and 16 only example values.
 
Upvote 0

alexanderjames

Member
Licensed User
Longtime User
Thank you Klaus

I'll try that method tonight, as I understand your sample this would be done in the main code and not in the Designer Scripts section. Is this correct ?

Many thanks
AJ
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Did you set any of these properties in the code ?
ListView1.SingleLineLayout.xxx
ListView1.TwoLinesLayout.xxx
ListView1.TwoLinesAndBitmap.xxx
If yes you need to use a scaling for those.
B4X:
scale = 1 + rate *  ((100%x + 100%y) / (320dip + 430dip) - 1)
ListView1.SingleLineLayout.ItemHeight = 40 * scale
ListView1.SingleLineLayout.Label.TextSize = 16 * scale
' etc
Where rate is the value of the ScaleRate you used in the DesignerScripts and 40 and 16 only example values.


I avoid talking about ScaleRate that just do not understand,
but in the formula you use 320x430 instead of 320x480.
I fear that the height of the headers change with the changing of the versions of the Android SDK (perhaps even changing the icon?)
 
Upvote 0
Top