panelview dragging not smooth

HarveyKwok

Member
Licensed User
Longtime User
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)
 

klaus

Expert
Licensed User
Longtime User
The code below works:
B4X:
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.

Best regards.
 
Upvote 0

HarveyKwok

Member
Licensed User
Longtime User
Klaus,
Thanks so much for you help, maybe my coding logic is wrong at initially
I am just want to move the panel follow my point (dragging).

The code below works:
B4X:
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.

Best regards.
 
Last edited:
Upvote 0

HarveyKwok

Member
Licensed User
Longtime User
Upvote 0

HarveyKwok

Member
Licensed User
Longtime User
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.
 
Upvote 0

HarveyKwok

Member
Licensed User
Longtime User
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
 
Upvote 0

HarveyKwok

Member
Licensed User
Longtime User
Problem code here

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
 

Attachments

  • test.png
    test.png
    22.8 KB · Views: 200
  • testdrag.zip
    7.2 KB · Views: 173
Upvote 0
Top