Android Question Listview label height

LucaMs

Expert
Licensed User
Longtime User
I would like to adjust the height of a label in a listview.

I found answers that recommend using the MeasureMultilineTextHeight of the StringUtils library, but I would like to avoid adding another library to my project.

Could someone extrapolate the function and add it to the Code snippets forum?

Thanks
 
I tried this code:
Code: Copy
Dim cnv As Canvas
Dim lbl As Label = ListView1.TwoLinesLayout.SecondLabel
cnv.Initialize(lbl)
Dim CanvasStringHeight As Float
CanvasStringHeight = cnv.MeasureStringHeight(Note, lbl.Typeface, lbl.TextSize)
Log("CanvasStringHeight = " & CanvasStringHeight)

but I get this error:
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:603)
...


for the statement: cnv.Initialize(lbl)
 
Upvote 0
Klaus already did it, or not?
 
Upvote 0
Did you add this in code or the Designer?

You will need to set the height of the ListView, which you don't seem to have done in the code you've posted.
 
Upvote 0
btw: luca, you only can set ONE height for Label and one height for SecondLabel in Listview.
Every item in the listview will have the same height (ListView<X>.TwoLinesLayout.Label.Height+ListView<X>.TwoLinesLayout.SecondLabel.Height)
You cannot set an different heigth for every listview-item

and this will be adapted to fontsize, color and so on too. Every item will look the same. It´s like "Little boxes" :D
 
Last edited:
  • Like
Reactions: eps
Upvote 0
btw: luca, you only can set ONE height for Label and one height for SecondLabel in Listview.
Every item in the listview will have the same height (ListView<X>.TwoLinesLayout.Label.Height+ListView<X>.TwoLinesLayout.SecondLabel.Height)
You cannot set an different heigth for every listview-item

and this we be adapted to fontsize, color and so on too. Every item will look the same.

Mostly yes you can only set the items once... however you can set two different sizes, but it is a bit of a fiddle.

Use TwoLinesLayout and TwoLinesAndBitmap - the two can be different, for the same ListView.
 
Upvote 0
ScrollView is the way to go for lots of items which are different heights. or customlistview or tableview or ULV (chargeable from Informatix).
 
Upvote 0
You cannot set the canvas to ListView1.TwoLinesLayout.SecondLabel because its Width = -1 by default to fit the parent view.

You could define:
Code: Copy
Dim bmp as Bitmap
bmp.InitializeMutable(2, 2)
cnv.Initialize(bmp)
Using a small bitmap for the canvas to minimize memory consumption.

In CustomListView you have AddTextItem which adjusts the height automatically.
 
  • Like
Reactions: eps
Upvote 0
Back
Top