Android Question Select item in CLV

Ilya G.

Active Member
Licensed User
Longtime User
Please tell me how to place selected item in the middle of screen? I already broke my brain :rolleyes:

1626617493127.png


1626617560630.png
 

Ilya G.

Active Member
Licensed User
Longtime User
But if the screen is narrow and only 4 elements are visible, how to show the selected one exactly in the center?

1626665122895.png
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Are all five circular elements in one panel? In a list of panels?

If so it is more complicated but doable, let us know.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
So it is a horizontal CLV. Now what is your question? How to scroll to the selected item and then make sure it is in the center of the screen?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
That is ok.
As @aeric pointed out you can simply scroll to the selected item with an adjustment based on screen size.

In other words, in CustomListView1_ItemClick, CustomListView1.JumpToItem (index + adjustmentForScreenwidth).
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
In B4Xpages center of screen is Root.width / 2
In standard android apps it is Activity.Width / 2
leftMarginTarget = the center of screen minus the panel width / 2

The underlying scrollView is found in CustomlistView1.sv

CustomListView1.JumpToItem (index)
CustomListView1.sv.ScrollViewOffsetX = CustomListView1.sv.ScrollViewOffsetX - leftMarginTarget

Let me know if this works.

Edit. If you looked at this a few minutes ago, I changed the + sign to a - sign
 
Last edited:
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
It doesn't seem to work

B4X:
clv.JumpToItem(index)
clv.sv.ScrollViewOffsetX = clv.sv.ScrollViewOffsetX + ((clv.AsView.Width / 2)  - (clv.GetPanel(index).Width / 2))


1626672131868.png
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
B4X:
    Dim x As XUI, p As B4XView = x.CreatePanel("")
    p.Width = 100dip
    p.Height = 100dip
    p.LoadLayout("category_2")
    clv.Add(p, 0)
then check
B4X:
    Dim item As CLVItem = clv.GetRawListItem(index)
    Log(DipToCurrent(100dip) & " / " & item.Size)

and get 225 /150, why is this happening?
 
Upvote 0
Top