Could anyone help to solve the following problem:
Attached is a panel for dragging, when I drag/move it , sometime it will vibrate itself abnormally , why it be happen?
(sorry for my bad in English)
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_DOWN
dx = X
dy = Y
pnlLeft = p.Left
pnlTop = p.Top
Case Activity.ACTION_MOVE
p.Left = (pnlLeft + X - dx)
p.top = (pnlTop + Y - dy)
Activity.Title = p.Left & " | " &p.top
Case Activity.ACTION_UP
End Select
End Sub
The problem in your code is that you modify the Left and Top properties insides the p_Touch even and the reference is modified every time you move.
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_DOWN
dx = X
dy = Y
pnlLeft = p.Left
pnlTop = p.Top
Case Activity.ACTION_MOVE
p.Left = (pnlLeft + X - dx)
p.top = (pnlTop + Y - dy)
Activity.Title = p.Left & " | " &p.top
Case Activity.ACTION_UP
End Select
End Sub
The problem in your code is that you modify the Left and Top properties insides the p_Touch even and the reference is modified every time you move.
Thanks for your help,
In fact, you let us in a rapid and easy way to code for android apps,
and the greatest thing is that, you improve this tool constantly.
klaus or anyone,
Could you show me more that
1. how to drag when I touch the panelview only; your code makes dragging anywhere on screen where I touch it
2. if there are 2 panelviews on the screen , how could drag the one which I touch it.
Erel,
I had tried the code from your post, It had run perfectly.
In fact, I want to trap the position when stop move, and run my sub, how can it do it in the Main - Activity, (not inside the your class)
I can do it, if use panel_touch with "Action" trapping
Please help to exam the following code, when I dragging the Square, I hope to show the Left position of the Square on the title bar, but it seems doesn't work correctly
B4X:
Sub Globals
Dim Button1 As Button
Dim Button2 As Button
Dim dv(2) As DraggableView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
dv(0).Initialize(Activity, Button1)
dv(1).Initialize(Activity, Button2
End Sub
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
Activity.Title = dv(0).left
End Sub