Android Question Fit n items in xCustomListView

Hello, I'm trying to fit n items inside the xCustomListView. Right now when i add the items, that last visible item is sometimes cut in half or barely showing. As i have multiple custom lists inside my app and the last visible item on every single custom list is not fully shown the appearance of the app is not as expected.

I created a method that takes the height of the custom list, the divider size and how many items should be fitted in the custom list when the scroll position is at it's initial state.
This method returns the height of the items that will go inside this custom list.

Calculate Row Height Method:
Public Sub CalculateRowHeight(ListViewHeight As Int, DividerHeight As Int, VisibleRows As Float) As Int
    Dim RowHeight As Int = ListViewHeight / VisibleRows
    
    'Since the xCustomListView adds a divider to the top of the list but doesnt add divider to the bottom of the list, the bottom divider will have to be split between the height of all the items.
    Dim LastRowDivider As Int = DividerHeight / VisibleRows
    
    Return RowHeight - DividerHeight - LastRowDivider
End Sub

This method kinda works, but the bigger the VisibleRows property is the more inaccurate the result is.
For example if VisibleRows is 10 a few pixels of the eleventh item will be visible.

If Someone can provide me with a better method to calculate the row height it will be great.
I also wonder how to calculate the VisibleRows property so it can fit more items when the screen height is bigger.
 
Not sure that I understand. You can add as many items as you like. It is a scrollable list.

Maybe post a screenshot.
Yeah I know,

What i meant is that, lets say for example there are 30 items in the scrollable list. I want exactly 5 of them to be shown on the initial state of the custom list and the other 25 should not be visible (until the user starts scrolling). If I hard code the height of the item to 70dips or 60dips, part of the 6th item is barely showing, or the 5th item is cut in half.

In Screenshot 1 the last VISIBLE row is cut in half, what i want to achieve in all custom lists is shown on the second screenshot. The last VISIBLE row is not cut and it's fully shown.

This is what I'm trying to achieve with the method mentioned above. I just pass how many rows should be VISIBLE and the method calculates what the height of each item should be so that the last VISIBLE row is not cut in half. But my method is sometimes inaccurate.

Thanks for your time!
 

Attachments

  • 1.png
    1.png
    133.5 KB · Views: 350
  • 2.png
    2.png
    135.7 KB · Views: 353
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I just pass how many rows should be VISIBLE and the method calculates what the height of each item should be so that the last VISIBLE row is not cut in half.
Based on what I have read in your previous post, I think you need to look at B4XTable in this case not xClv. With B4XTable you scroll horizontally by every page and you can set the number of visible rows in each page and see the data without any truncation. There are lots of examples you can check out and see if it suits your needs. Run the example here:
 
Upvote 0
Top