Android Question How to BringToFront or increase elevate for imageviews or panels inside gestureDetector?

Toni

Member
Licensed User
Longtime User
I'am a little bit despareted. I like to drag some panels or imageviews on a playfield. Works fine but how can I bring the active panel or imageview to front or at a higher elevation and at which location ideally in the code? Maybe my declaration of the gestureDetector is wrong, you see I'm not a very experienced user. Therefore a second question. I like these views also to rotate (by 90° steps, maybe enough but a smooth animation will be also welcome) and flip (in two different gesturedetector subs). As I read in the graphics booklet an imageview offers naturaly both methods. On the other hand it should be no problem to get the bitmap of a panel. So what do you suggest I should prefer for my belongings, panels or imageviews? Excuse my bad english and please answer in relative short sentences, thank you! German answers are also welcome!:D the shortened but full working code is also attached as zip.

EdiT: the views are located on another panel. Don't know if this is important.

3 snippets: GD declarations and GD onDrag Sub:
    Dim GD0 As GestureDetector
    Dim GD1 As GestureDetector
    Dim GD2 As GestureDetector
    Dim GD3 As GestureDetector
    Dim GD(4) As GestureDetector
   
    ...
   
    GD=Array As GestureDetector(GD0, GD1, GD2, GD3)
   
    piece=Array As Panel(pcs0, pcs1, pcs2, pcs3)  
   
    Dim i As Int
   
    For i= 0 To 3
        GD(i).SetOnGestureListener(piece(i), "Gesture")
    Next  
    ....
   
    Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
   
    Dim i As Panel=Sender
    Dim j As Int
    j=i.Tag
    Log("no "  & "  " & j)
    'piece(j).Elevation=5dip        'no crash , but also no reaction  
    'piece(i).bringtofront crashes as well as piece(j).bringtofront
    i.left = Max(9dip, Min(i.Left + deltaX, bg.width -i.Width-9dip))
    i.top = Max(9dip, Min(i.Top + deltaY, bg.height-i.height))
    If DipToPixels(i.top)   < 340 Then
        i.SetLayoutAnimated(0,i.left, i.top, states.Get("width" & j), states.Get("height" & j))
    Else
        i.SetLayoutAnimated(0,i.left, i.top, states.Get("width" & j)*0.6, states.Get("height" & j)*0.6)
    End If
End Sub
 

Attachments

  • game.zip
    19.3 KB · Views: 3

klaus

Expert
Licensed User
Longtime User
Change your Gesture_onTouch routine to this:

B4X:
Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Dim i As Panel = Sender
    Dim j As Int
    j = i.Tag

    Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)

    Select Action
        Case GD(j).ACTION_DOWN
            i.BringToFront
        Case GD(j).ACTION_MOVE
        Case GD(j).ACTION_UP
    End Select
    Return True
End Sub

Or like this:
B4X:
Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Dim i As Panel = Sender
    Dim j As Int
    j = i.Tag

    Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)
    
    If Action = GD(j).ACTION_DOWN Then
        i.BringToFront
    End If
    Return True
End Sub
 
Last edited:
Upvote 0

Toni

Member
Licensed User
Longtime User
One question again: what do you think is better for my belongings, using a panel or a an imageview or doesn't matter?
Best regards
 
Upvote 0
Top