Android Question How to move a panel to a new location at RunTime?

Mattiaf

Active Member
Licensed User
Hi, I have the need to move a panel on top of a item into a CustomListView.
I'm using a panel as a Context Menu, but I'm not able to show it right on top of the clicked item..
I'm looking into the forum but I can only find float windows classes, but that's not right what I am looking for..

Thanks
 
Solution
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top
    pnlContextualMenu.Visible = True
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(300, CustomListView1.AsView.Left - pnlContextualMenu.As(B4XView).Width, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
End Sub

1.gif

LucaMs

Expert
Licensed User
Longtime User
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top
    pnlContextualMenu.Visible = True
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(300, CustomListView1.AsView.Left - pnlContextualMenu.As(B4XView).Width, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
End Sub

1.gif
 
Upvote 1
Solution

Mattiaf

Active Member
Licensed User
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top
    pnlContextualMenu.Visible = True
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(300, CustomListView1.AsView.Left - pnlContextualMenu.As(B4XView).Width, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
End Sub

View attachment 136408
Hi Luca thank you so much for your help. Since I m using a blurred panel, would it be possible to center it right above the clicked item?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi Luca thank you so much for your help. Since I m using a blurred panel, would it be possible to center it right above the clicked item?
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top + CustomListView1.GetPanel(Index).Height
    lblMenu.Text = "Menu " & Value
    pnlContextualMenu.Visible = True
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(300, CustomListView1.AsView.Left + (CustomListView1.AsView.Width - pnlContextualMenu.As(B4XView).Width) / 2, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
End Sub

1.gif


Obviously you don't need to do that animation, it's just an example.
It would be nicer if the menu appeared gradually, increasing its visibility from 0 to 255 or directly in its position.

B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top + CustomListView1.GetPanel(Index).Height
    lblMenu.Text = "Menu " & Value
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(0, CustomListView1.AsView.Left + (CustomListView1.AsView.Width - pnlContextualMenu.As(B4XView).Width) / 2, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
    pnlContextualMenu.SetVisibleAnimated(150, True)
End Sub
1.gif
 
Last edited:
Upvote 0

Mattiaf

Active Member
Licensed User
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Top As Int = CustomListView1.GetPanel(Index).Parent.Top - CustomListView1.sv.ScrollViewOffsetY + CustomListView1.GetBase.Top
    pnlContextualMenu.Visible = True
    pnlContextualMenu.As(B4XView).SetLayoutAnimated(300, CustomListView1.AsView.Left - pnlContextualMenu.As(B4XView).Width, Top, pnlContextualMenu.As(B4XView).Width, pnlContextualMenu.As(B4XView).Height)
End Sub

View attachment 136408
Thanks Luca, that's perfect!
 
Upvote 0
Top