B4J Question CLV tree view image size

svmenifee

Member
I'm trying to replicate Erel's JSON tree parser for incorporation into my app, but hitting a slight snag. See images below.



Image on the right users CustomListView in Designer. Image on right is Ere's original JsonTree that uses the old TreeView and Scene Builder.

Here's the thing: I grabbed the three image files (green, blue, red) used in the original, wanting the same look. But CustomListView insists on enlarging this small 16x16 bitmaps, and no matter what I do I cannot seem to change their size to look more like the original. I can reduce the height of the tree panels with Tree.DefaultHeight, but this only crops the images rather than resize them. Image.resize seems to do nothing, even with a tree.refresh.

No doubt something "obvious", but if anyone knows how to change the way CLV displays those images it would save me some headache.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use the source code of CLVTree instead of the library.
Unzip the b4xlib file, extract CLVTree.bas and Files\arrow.png and add to your project.
Also add a reference to XUI Views library.

Change the GetItemUI sub to:
B4X:
Private Sub GetItemUI As B4XView
    If UICache.Size > 0 Then
        Dim p As B4XView = UICache.Get(0)
        UICache.RemoveAt(0)
        Return p
    End If
    p = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, mCLV.AsView.Width, DefaultHeight)
    p.AddView(XUIViewsUtils.CreateB4XImageView.mBase, 0, p.Height / 2 - 10dip, 20dip, 20dip)
    p.GetView(ARROW_INDEX).Tag.As(B4XImageView).mBackgroundColor = xui.Color_Transparent
    p.GetView(ARROW_INDEX).Tag.As(B4XImageView).Bitmap = arrowbmp
    
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    iv.ResizeMode = "NONE"  '<-------
    p.AddView(iv.mBase, 0, p.Height / 2 - 15dip, 30dip, 30dip)
    
    p.GetView(IMAGE_INDEX).Tag.As(B4XImageView).mBackgroundColor = xui.Color_Transparent
    Dim lbl As B4XView = XUIViewsUtils.CreateLabel
    lbl.Font = mCLV.DesignerLabel.As(B4XView).Font
    lbl.TextColor = mCLV.DesignerLabel.As(B4XView).TextColor
    lbl.SetTextAlignment("CENTER", "LEFT")
    p.AddView(lbl, 0, 0, p.Width, p.Height)
    Dim tp As B4XView = xui.CreatePanel("TouchPanel")
    p.AddView(tp, 0, 0, 0, 0)
    Return p
End Sub
 
Upvote 0

svmenifee

Member

Works perfectly. I think I will name my first grandson Erel. Or if a girl, Erela.

Thanks for your response and for ignoring my typos and left/right confusion.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…