Listview height strange behaviour.

BasicBert

Member
Licensed User
Hi you all.
:sign0085: This is my first post on this forum, so please forgive me when I'm not following any rules.
I first tried to solve my problem by reading as much posts as I could find about it, but that doesn't help. After three days of looking around and trying, I need help.

This is my problem :

I'm defining a Listview in my layout by code, which works fine.
But then I want the TwoLinesLayout's first and second line to be set to a bigger height, to show a text that's longer than the width of the Listview. I just want to do this at defining the ListView, not while already defined.
Now I'm puzzled by some strange behaviour :

When I change the height of the first line, it does not change!
When I change the height of the second line, it does not change either!
Now when I change the ItemHeight the first lines Height does not change, but the second lines Height DOES!

Correct me if I'm wrong, but I would suspect that setting the Height for the first line should change it, as it should do with the second lines. Of course, the total ItemHeight must be the same or more as the sum of the first and second lines.

A sample of my code :

B4X:
   lstWijn.Initialize("")
   lstWijn.Color = Colors.Blue
   lstWijn.ScrollingBackgroundColor = Colors.Blue
   lstWijn.FastScrollEnabled = True
   lstWijn.TwoLinesLayout.Label.Width = 80%x
   lstWijn.TwoLinesLayout.SecondLabel.Width = 80%x
   lstWijn.TwoLinesLayout.Label.TextSize = 18
   lstWijn.TwoLinesLayout.SecondLabel.TextSize = 18
   lstWijn.TwoLinesLayout.Label.Color = Colors.Blue
   lstWijn.TwoLinesLayout.Label.TextColor = Colors.Yellow
   lstWijn.TwoLinesLayout.SecondLabel.Color = Colors.Blue
   lstWijn.TwoLinesLayout.SecondLabel.TextColor = Colors.Yellow   
   lstWijn.TwoLinesLayout.Label.Gravity = Gravity.TOP   
   lstWijn.TwoLinesLayout.SecondLabel.Gravity = Gravity.TOP
   
   lstWijn.TwoLinesLayout.Label.Height = 100
   lstWijn.TwoLinesLayout.SecondLabel.Height = 100
'   lstWijn.TwoLinesLayout.ItemHeight = lstWijn.TwoLinesLayout.Label.Height + lstWijn.TwoLinesLayout.SecondLabel.Height
   Activity.AddView(lstWijn, 0, 24%y, 100%x, 71%y)

I'm defining the properties of the Listview lstWijn in the first lines of the code.
It's the last lines that keep me puzzled :

B4X:
   lstWijn.TwoLinesLayout.Label.Height = 100
   lstWijn.TwoLinesLayout.SecondLabel.Height = 100
'   lstWijn.TwoLinesLayout.ItemHeight = lstWijn.TwoLinesLayout.Label.Height + lstWijn.TwoLinesLayout.SecondLabel.Height
   Activity.AddView(lstWijn, 0, 24%y, 100%x, 71%y)

Changing the heights on both lines from 100 to any other value makes no difference, the lines will all be the same "standard" size.
When changing both heights and uncommenting the ItemHeight calculation, only the second lines of the Listview become bigger and show the displayed text wrapped around as I like it. It's only too high, as if the height for the first line is also added to the second line.
But I also want the first lines to be changed and the second lines to the amount that I specified, no more, no less!!

I have read that a ScrollView is much more flexible, but I'm a newbie and I just want a simple list (=listview) of two items per record. Apart from the problems with sizing, it suits me very well.

Thanks in advance for repying.
 

klaus

Expert
Licensed User
Try this code:
B4X:
lstWijn.TwoLinesLayout.Label.Height = 100dip
lstWijn.TwoLinesLayout.SecondLabel.Top = lstWijn.TwoLinesLayout.Label.Height
lstWijn.TwoLinesLayout.SecondLabel.Height = 100dip
lstWijn.TwoLinesLayout.ItemHeight = lstWijn.TwoLinesLayout.Label.Height + lstWijn.TwoLinesLayout.SecondLabel.Height
Activity.AddView(lstWijn, 0, 24%y, 100%x, 71%y)
You need to set also the Top property of the second line.

Best regards.
 
Upvote 0

BasicBert

Member
Licensed User
Klaus,
This line :
B4X:
lstWijn.TwoLinesAndBitmap.SecondLabel.Top = lstWijn.TwoLinesAndBitmap.Label.Height

did the trick, so I'm happy.

It also works with a Listview with TwoLinesAndBitmap, as you might expect.

Can I ask you how to prevent bitmaps in these Listviews to stretch the content?

Thankfully and with regards,

BasicBert.
 
Upvote 0

BasicBert

Member
Licensed User
Sorry Klaus,

but I can't find the right place to define these dimensions.
I expected it to be one or more properties in the listview, but I can't find it.
I'm constantly looking in the Beginner's Guide because I think I have to do my homework before bothering somebody else.

Would you please give me another hint ? :sign0163:

Regards,
BasicBert.
 
Upvote 0

klaus

Expert
Licensed User
Where do your bitmaps come from?
Do you really not know their dimensions or at least their width/height ratio.
When you load a bitmap you know it's width an height.
Then you can adapt the Left, Top, Widht and Height properties like
ListView1.TwoLinesAndBitmap.ImageView.Left = xx
Have a look here.
Do you have any code we could look at ?

Best regards.
 
Upvote 0

BasicBert

Member
Licensed User
:sign0060:

Klaus,

It was the Imageview property that I was looking for, but didn't find.
I tried it and now I can adjust the bitmaps sizes.

I'm loading the bitmaps from external memory and the related files do not all have the same dimensions. Usually the height will be the same, but the width may (and will) differ.

I include part of my code which fills the listview lstWijn with a selection of the entries in a Table (which is loaded from a CSV-file earlier). This works fine for me, now I just (?) want to adapt the (height and) width of the bitmap so that it doesn't stretch. I don't mind if the bitmap would be padded with black or white pixels to fill up If I can only define a width and height for all bitmaps and not for every single bitmap.

As you may notice, my App would be about presenting data from my PC-database filled with my collection (in my "cellar" or already drunk) of wine.
I added a screenshot of what I have build op to now.

B4X:
Sub VulListView                           'Fill lstWijn with a selection of records from the Table
   Dim TableEntry(Table.Size) As Int         'Array with index of ListView-entry to Table-entry
   Dim Regel As Int : Regel = 0            'Counter for index of lstWijn-entries
   lstWijn.Clear                        'Clear Listview
   For i = 0 To Table.Size-1               'Loop through Table
      Dim sColumn() As String
      sColumn = Table.Get(i)               'Get an entry from the Table ( = 1 record)
      If sColumn(KleurHeader) = Keuze Then   'If entry is wanted, put two fields plus bitmap (from a file) of the record in the Listview
         lstWijn.AddTwoLinesAndBitmap(sColumn(Header1),sColumn(Header2), LoadBitmap(File.DirRootExternal, PathImages & sColumn(WijnBitmap)))
         TableEntry(Regel) = i            'Save index for later use in the array TableEntry
         Regel = Regel + 1               'Next index counter
      End If
   Next                              'next Table-entry to process
End Sub

Your help is nicely boosting my App, which I have been thinking of to program for quite some time. I've been a TRS-80 Basic and a bit VB hobby-programmer in the 80's and interested again in programming for Android.
B4A is an ideal tool because it reminds me a lot of those old days. I tried starting with Eclipse, but only creating the obvious "Hello World" app takes a lot of hard to understand code.
So thumbs up for B4A and thanks to Erel, Klaus and everyone on this forum.

Greetings,

BasicBert.
 

Attachments

  • Wijnopslag01.png
    Wijnopslag01.png
    66.2 KB · Views: 205
Upvote 0
Top