Android Question [SOLVED] xCustomListView, Label Horizontal Alignment didn't work

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I have these codes
B4X:
Sub createSmmryItem As Panel
    Dim p As Panel
    p.Initialize("")
    p.LoadLayout("lySmmry")
    p.SetLayout(0, 0, 100%x, pnlSmmry.Height)
    p.Color = Colors.RGB(48,48,48)
    Return p
End Sub

Sub Test
   Private clv As CustomListView
   clv.Clear
   clv.Add(createSmmryItem,0) 
End Sub

In layout "lySmmry", there are labels that Horizontal alignment set to right/center, but it didn't work, it always display with left alignment.
My xCustomListView version is 1.73 same as online version.

Are there something wrong with my codes?
 

mangojack

Expert
Licensed User
Longtime User
Same version of xCLV. Layout containing 2 Labels , Horizontal Alignment = RIGHT & Horizontal Alignment = CENTER_HORIZONTAL.
Displays as Expected.

B4X:
Sub createSmmryItem As Panel
    Dim p As Panel
    p.Initialize("")
    p.LoadLayout("clvItems")
    p.SetLayout(0, 0, 100%x, pnlSmmry.Height)
    Label1.Text = "Test1"
    Label2.Text = "Test2"
    p.Color = Colors.RGB(48,48,48)
    Return p
End Sub

Maybe a small example might be helpful.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Setting lblTitleSmmry's Horizontal ANCHOR to LEFT (not Left & Right) seems to solve the issue.

As to why , I cannot say. Hopefully someone can explain further.


ps: just to add, often I have Label ANCHOR set to Left/Right and ALIGNMENT set to Center, so I do not understand why it is not working in this case.
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Hi guys,

I have these codes
In layout "lySmmry", there are labels that Horizontal alignment set to right/center, but it didn't work, it always display with left alignment.
My xCustomListView version is 1.73 same as online version.

Are there something wrong with my codes?
You need to set a width for p.
B4X:
Sub createSmmryItem As Panel

    Dim p As Panel
    p.Initialize("")
    p.Width=clv.GetBase.Width 'set a width for Panel
    p.LoadLayout("lySmmry")
    p.SetLayout(0, 0, 100%x, pnlSmmry.Height)
    p.Color = Colors.RGB(48,48,48)
    Return p

End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
When I was trying to find the issue , the fact @incendio was seting the width (100%x) , seemed OK
I only realize now the different method of creating the panel ( not utilizing xui / b4xview), wich is probably why I have never encountered this issue.

B4X:
Sub  CreateRow(text As String, width As Int, height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, width, height)
    p.LoadLayout("clvItems")
    Label1.Text = "This is Label 1  run #" & text
    Return p
End Sub
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
You need to set a width for p.
B4X:
Sub createSmmryItem As Panel

    Dim p As Panel
    p.Initialize("")
    p.Width=clv.GetBase.Width 'set a width for Panel
    p.LoadLayout("lySmmry")
    p.SetLayout(0, 0, 100%x, pnlSmmry.Height)
    p.Color = Colors.RGB(48,48,48)
    Return p

End Sub
This codes works for me, thanks for your help.
 
Upvote 0
Top