Android Question Drag and Drop - Match

rafaelbr20

Member
Licensed User
Longtime User
Hi Everyone,

I would like a help !

I will have one Image/Panel at left, and 3 Images/Panels at Right.

A child has to Drag and Drop the left image to a correct right image, if he drop onto a correct image, i'll show some message for example, and if it is not correct, i´ll send image to original position !

Hou can i do it?

Thanks so much !

Rafael
 

rafaelbr20

Member
Licensed User
Longtime User

Thanks Erel !

I'm using it. How can i detect if one panel/view is on top of other one ? I need to check it. I can detect comparing X and Y on Panel1_Touch , but if i use this way to check , a child has to put the panel exacly on top, same X and Y, and it will be very difficult ! If there is some way to detect that one panel is on top of another, will be perfect , something like docking areas !

Thanks so much !

Rafael
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to implement it. The exact details depend on your requirements.

Something like:
B4X:
Sub DoTheyOverlap(v1 As View, v2 As View) As Boolean
   'c = center
   Dim cx1 As Float = v1.Left + v1.Width / 2
   Dim cy1 As Float = v1.Top + v1.Height / 2
   Dim cx2 As Float = v2.Left + v2.Width / 2
   Dim cy2 As Float = v2.Top + v2.Height / 2
   Return Abs(cx2 - cx1) < v1.Width / 2 + v2.Width / 2 And Abs(cy2 - cy1) < v1.Height / 2 + v2.Height / 2
End Sub
 
Upvote 0

rafaelbr20

Member
Licensed User
Longtime User
You will need to implement it. The exact details depend on your requirements.

Something like:
B4X:
Sub DoTheyOverlap(v1 As View, v2 As View) As Boolean
   'c = center
   Dim cx1 As Float = v1.Left + v1.Width / 2
   Dim cy1 As Float = v1.Top + v1.Height / 2
   Dim cx2 As Float = v2.Left + v2.Width / 2
   Dim cy2 As Float = v2.Top + v2.Height / 2
   Return Abs(cx2 - cx1) < v1.Width / 2 + v2.Width / 2 And Abs(cy2 - cy1) < v1.Height / 2 + v2.Height / 2
End Sub

Thanks so Much Erel !! Perfect !
 
Upvote 0
Top