B4J Question For xCustomListView, How To Only Show Scrollbar When It Is Needed

cklester

Well-Known Member
Licensed User
At first, my CLV does not have enough items to require a scrollbar, so I hide the scrollbar. However, once enough items are added, or the view is resized and now does not show the entire list, I'd like to enable the scrollbar visibility.

I'm using this code to determine the need for the scrollbar, and it works, but I'm not sure how to show the scrollbar:

B4X:
    If Not(clv_Categories.LastVisibleIndex = clv_Categories.Size-1 And _
            clv_Categories.FirstVisibleIndex = 0) Then
        'can't see all the categories, so enable the scrollbar!
    End If
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the default behavior. Don't hide the scrollbar.

kRwpqyxA5E.gif
 
Upvote 0

cklester

Well-Known Member
Licensed User
None of my xCustomListViews have ever behaved like that. If there doesn't need to be a scrollbar, it still shows space for it, even though it doesn't draw the scrollbar.

I'm applying a width to the clv item of its clv parent. Could that be the problem?
 
Upvote 0

cklester

Well-Known Member
Licensed User
Which panel should not be transparent? It seems none of my panels are transparent.

B4X:
Sub LoadLibrary
    For Each article As String In articles
        Private li As LibraryItem
        li.Initialize
        Private w As Int = clv_Articles.GetBase.Width
        Private p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0,0,0,DipToCurrent(w),90dip)
        p.LoadLayout("LibraryItem")
        p.Color = xui.Color_White
        lbl_ArticleLink.Text = article
        lbl_Description.Text = "Description for " & article
        lbl_Description.Enabled = False
        chk_Archived.Checked = False
        clv_Articles.Add(p,li)
    Next
End Sub

The panel (above) is set to white. The clv_Articles has a background of white. The form of the CLV item has a background of white. I still get this:

1605048913225.png


Now with scrollbar:

1605048967417.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My mistake. The behavior you see is the expected behavior. My test was actually behaving differently due to the way it added the items.

You can change the "divider color" to white. It will make it look better. You can also set the divider height to 0 and add your own divider (2 pixels tall panel) in the item itself.
 
Upvote 0

cklester

Well-Known Member
Licensed User
The behavior you see is the expected behavior.

Couldn't I, by using a Resize event, see if the FirstItem is visible and the LastItem is visible to determine whether or not to show the scrollbar? This is obviously just for aesthetics, but I think it would look nicer.

B4X:
Sub clv_Categories_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    If clv_Categories.FirstVisibleIndex = FirstIndex And clv_Categories.LastVisibleIndex = LastIndex Then
        'hide the scrollbar -- How to do this bit?
    Else
        'show the scrollbar -- How to do this bit?
    End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The VisibleRangeChanged event is not relevant.

You need to do something like:
B4X:
Sub MainForm_Resize (Width As Double, Height As Double)
    If clv1.FirstVisibleIndex = 0 Or clv1.LastVisibleIndex = clv1.Size - 1 Then
        Sleep(5)
        For i = 0 To clv1.Size - 1
            Dim p As B4XView = clv1.GetPanel(i)
            p.Width = clv1.AsView.Width
            p.Parent.Width = p.Width
        Next
    End If
End Sub
 
Upvote 0
Top