Android Question [Solved] Rotating custom view with touch_action

angel_

Well-Known Member
Licensed User
Longtime User
I use the link example, after rotating custom view I try to move it but it disappears.

B4X:
Public Sub CrearView(xPanel As B4XView, Height As Int, Width As Int, Top As Int, Left As Int)
    mLeft = Left
    mTop = Top
    mWidth = Width
    mHeight = Height
    
    xBase = xui.CreatePanel("xBase")
    xBase.Color = xui.Color_White
    Tag = xBase.Tag
    xBase.Tag = Me
    
    xPanel.AddView(xBase, mLeft, mTop, mWidth, mHeight)
    
    imgv.Initialize("")
    xBase.AddView(imgv, 0, 0, mWidth, mHeight)
    imgv.Bitmap = LoadBitmap(File.DirAssets, "img.png")
    
    innerView = xBase
    
    ACTION_DOWN = xBase.TOUCH_ACTION_DOWN
    ACTION_MOVE = xBase.TOUCH_ACTION_MOVE
    ACTION_UP = xBase.TOUCH_ACTION_UP
    
    Dim r As Reflector
    r.Target = xBase
    r.SetOnTouchListener("Panel1_Touch")
End Sub

Public Sub Rotation(Angle As Int)
    xBase.Rotation = xBase.Rotation + Angle
End Sub

Private Sub Panel1_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
    If ACTION = ACTION_DOWN Then
        downx = x
        downy = y
    Else
        innerView.Left = innerView.Left + x - downx
        innerView.Top = innerView.Top + y - downy
        xBase.Left = innerView.Left
        xBase.Top = innerView.Top
    End If

    Return True
End Sub


20-09-22-11-49-23.gif
 

Attachments

  • TestRotate.zip
    19.3 KB · Views: 174
Top