Sub Globals
Dim p As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
p.Initialize("p")
Activity.AddView(p, 0, 0, 100%x, 100%y)
End Sub
Sub p_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Select Action
Case Activity.ACTION_DOWN
Log("down")
Case Activity.ACTION_MOVE
Log("move")
Case Activity.ACTION_UP
Log("up")
End Select
Return True
End Sub
You should return True. Otherwise the panel just passes the event to the underlying view and no longer handles the current touch.
Please note that while the down event is fired only on the panel area, the other two events are working also when going with the mouse/finger out of the panel area.
I attach here a piece of code and pictures which I used for vertical seekbar. The background image includes the gray part of the seekbar.
B4X:
Sub volPnl_Touch(Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Dim h As Double
volume.height = Max(Min(volpnl.Height - y, volpnl.Height),0)
volume.Top = 405 - volume.height
caret.top = volume.Top - caret.height/2
h = 1 - y/volpnl.Height
mp.SetVolume(h,h)
Return True
End Sub
notes: the panel covers the "seekbar" from top to bottom, the bottom in my app is 405. "volome" imageview holds the yellow bar and "caret" another imageview holding the knob.
The max-min line is to limit the volume size so it doesn't go beyond the 0-100% as a result of the abovementioned phenomena.
Other colors may be used of course.