java - Android: Limit drag & drop of object -


I have an activity I have a relative layout on this activity. On this layout I have placed several custom objects from a class Which extend the relational layout.
It looks like a chess (it's not, but so you know what I'm talking about).
Now I want to touch any one of this object and drag it into one of the 4 adjacent fields, swip it against it.
I thought Android Drag & amp; Drop

I used the setOnTouchListener and setOnDragListener for every object, so every object can be touched and dragged on to another object.
I used the tutorial, so you just have to read it compared to code, but here should be easy:

  @Override Public Boolean onTouch (see v, MotionEvent e) {If (e.getAction () == MotionEvent.ACTION_DOWN) {DragShadowBuilder shadowBuilder = New View.DragShadowBuilder (v); V.startDrag (faucet, shadowbilder, v, 0); Back true; } Other {return false; }} @Override Public Boolean OnDrag (v View DragEvent E) {if (e.getAction () == DragEvent.ACTION_DROP) {View View = (see) e.getLocalState (); ViewGroup = (ViewGroup) view.getParent (); From.removeView (see); MyCustomViewClass = (MyCustomViewClass) v; To.addView (see); View.setVisibility (View.VISIBLE); } Back true; }  

Now I am wondering how can I limit where an object can be removed. I want it to be able to be taken just to the adjacent areas (not only by limiting the draglistener, I also want to move objects beyond this, no matter how far the finger tries to drag) .
I hope what you say to me, if not, then please ask.
So the question is what can I do with this drag and amp; Do I think it can somehow find out where the finger is before falling? Is it possible to pull straight X and Y axis? Or is there a way of knowing the direction of the pulling movement, which gives me permission of 1) I know the object with which I will swap and 2) I would like to move other objects before drop, Is the object just swapping? >

Edit: I got the direction because I can calculate it from view.getX , view.getY and startobject DragEvent ACTION_ENTERED goes into v.getX and v.getY inDrag (the object I'm coords from). Now I try to figure out how to set the status of the dragshot to either object, I want to end it, or just drag it in my direction and drag the drag on the next object.
More help or ideas still appreciate.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -