dragging a panel

Jack Cole

Well-Known Member
Licensed User
Longtime User
I've written a very simple program to drag a panel just to get the basic concept for another app I'm working on. It sort of works, but behaves very strangely.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim p As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
p.Initialize("dragpanel")
activity.AddView(p,100%x/2-50dip,100%y/2-50dip,100dip,100dip)
p.Color=Colors.gray
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub move(v As View,x As Float,y As Float)
   v.Left=x-50dip
   v.Top=y-50dip
   Log("x=" & x & ", y=" & y)
End Sub

Sub dragpanel_Touch (Action As Int, X As Float, Y As Float)
   If action=2 Then
      move(p,x,y)
   End If
End Sub

The panel flickers and jumps back and forth between the position I am touching and the upper part of the screen. I logged the x,y locations and it essentially does the same thing. I was tempted to think it might be something with my digitizer on my phone, but it seems to work fine in other apps when dragging an object. Here is an example of what I get in the log.

x=75.11891174316406, y=89.21148681640625
x=229.76422119140625, y=506.21148681640625
x=72.84349060058594, y=89.21148681640625
x=225.92276000976563, y=506.21148681640625
x=69.54167175292969, y=89.21148681640625
x=223.56809997558594, y=506.21148681640625
x=67.16056823730469, y=89.21148681640625
x=221.18698120117188, y=504.434326171875
x=66.72662353515625, y=89.434326171875
x=217.31910705566406, y=504.434326171875
x=66.34553527832031, y=86.768798828125
x=213.91159057617188, y=504.768798828125
x=65.96443176269531, y=86.768798828125
x=212.9644317626953, y=501.214599609375
x=75.23983764648438, y=84.4375
x=216.6209259033203, y=500.5489501953125
x=86.81707763671875, y=80.106201171875
x=220.22459411621094, y=500.106201171875
x=92.55284118652344, y=76.55206298828125
x=228.8282470703125, y=499.66351318359375

Any help or ideas would be greatly appreciated.

Thanks,
Jack
 

sorex

Expert
Licensed User
Longtime User
When I try that initial code + the fix from agraham the block still wobbles when I drag it.

Any idea what could cause this?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I don't get it.

On my phone it works fine but on the tablet it wobbles/jumps when I drag it.
 
Upvote 0
Top