Android Question How to "release" a panel after being dragged?

Mattiaf

Active Member
Licensed User
Hi, I'm following @Erel topic about the DraggableView class in order to get a panel to move around.
That solution works great, but I also have 2 buttons in the panel.
Unfortunately I am not able to click them, since clicking on them is tricking the software to assume that I'm dragging, while I'm pressing the button instead..
Am I doing something wrong or am I missing something? Do i need to "drop it"?
Also, how can i make sure the borders of the panel don't go over the limit of the screen while dragging?
p.s. Im working with b4x pages
Thanks you so much
 
Solution
If you look at the code of the draggableView, the working principle is to add a transparent panel on top of your panel, so the added panel will block the touch event to the views under that. It will not work for your scenario. You can refer to the drag code and directly operate on your panel in touch event.

how can i make sure the borders of the panel don't go over the limit of the screen while dragging?
During dragging, check the panel's left and top value and if they <= 0 then set them to 0. Right and bottom side then the width and height of panel should be considered and compare to the screen width and height.

kimstudio

Active Member
Licensed User
Longtime User
If you look at the code of the draggableView, the working principle is to add a transparent panel on top of your panel, so the added panel will block the touch event to the views under that. It will not work for your scenario. You can refer to the drag code and directly operate on your panel in touch event.

how can i make sure the borders of the panel don't go over the limit of the screen while dragging?
During dragging, check the panel's left and top value and if they <= 0 then set them to 0. Right and bottom side then the width and height of panel should be considered and compare to the screen width and height.
 
Upvote 2
Solution

Mattiaf

Active Member
Licensed User
If you look at the code of the draggableView, the working principle is to add a transparent panel on top of your panel, so the added panel will block the touch event to the views under that. It will not work for your scenario. You can refer to the drag code and directly operate on your panel in touch event.


During dragging, check the panel's left and top value and if they <= 0 then set them to 0. Right and bottom side then the width and height of panel should be considered and compare to the screen width and height.
hmm can you explain me better via code what you mean in your first statement? how can I remove the added panel? thanks!!
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Could you post a small project?
 
Upvote 0

Mattiaf

Active Member
Licensed User
Hy Teddy, I'm trying Erel code inside a new fresh project and I'm using a panel with two buttons inside.. nothing more than that
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hy Teddy, I'm trying Erel code inside a new fresh project and I'm using a panel with two buttons inside.. nothing more than that
The code just adds view panel to activity, button will cover the panel, I wonder how you drag it.
 
Upvote 0

Mattiaf

Active Member
Licensed User
To whoever might needs
B4X:
'on class global
Private downx, downy As Int
    Private ACTION_DOWN, ACTION_MOVE, ACTION_UP As Int
    
'on initialize...
ACTION_DOWN = ACTION_DOWN
    ACTION_MOVE = ACTION_MOVE
    ACTION_UP = ACTION_UP
    
'under panel touch event
    If Action = ACTION_DOWN Then
        downx = x
        downy = y
    Else
        pnlMenuModificaEliminaChiave.Left = pnlMenuModificaEliminaChiave.Left + x - downx
        pnlMenuModificaEliminaChiave.Top = pnlMenuModificaEliminaChiave.Top + y - downy
        pnlMenuModificaEliminaChiave.Left = pnlMenuModificaEliminaChiave.Left
        pnlMenuModificaEliminaChiave.Top = pnlMenuModificaEliminaChiave.Top
    End If
    Return True
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Glad you figured it out. There is no need for these two lines:

pnlMenuModificaEliminaChiave.Left = pnlMenuModificaEliminaChiave.Left
pnlMenuModificaEliminaChiave.Top = pnlMenuModificaEliminaChiave.Top
 
Upvote 0

Mattiaf

Active Member
Licensed User
Glad you figured it out. There is no need for these two lines:

pnlMenuModificaEliminaChiave.Left = pnlMenuModificaEliminaChiave.Left
pnlMenuModificaEliminaChiave.Top = pnlMenuModificaEliminaChiave.Top
in some how, the panel, when dragged, is flickering.. Might be because I remove the lines you told me to or is the example bug? Thanks
 
Upvote 0
Top