I want to animate a ShadowView
to some coordinates (to destination view).
I'm using D&D and if user drops (DragEvent.ACTION_DROP
) then the view in some area I want to animate the view (from the drop location) to some destination view.
I don't want to animate view from the source location but want to do from the DROP location.
I tried a lot of things but nothing works. How can I get access to the ShadowView
? This also not working:
EventDragShadowBuilder.getView()
I think TranslateAnimation
should work for this but I need access to the "shadow" view during the D&D.
Image:
First implement onTouchlistener on the view
llDragable.setOnTouchListener(this);
Make a view draggable
@Override public boolean onTouch(View view, MotionEvent event) { float dX = 0; float dY = 0; switch (view.getId()){ case R.id.dragableLayout :{ switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dX = view.getX() - event.getRawX(); dY = view.getY() - event.getRawY(); lastAction = MotionEvent.ACTION_DOWN; break; case MotionEvent.ACTION_MOVE: view.setY(event.getRawY() + dY); view.setX(event.getRawX() + dX); lastAction = MotionEvent.ACTION_MOVE; break; case MotionEvent.ACTION_UP: //Animate animate(); if (lastAction == MotionEvent.ACTION_DOWN) //Toast.makeText(DraggableView.this, "Clicked!", Toast.LENGTH_SHORT).show(); break; default: return false; } return true; } } return false; }
Then you can use object animator at case MotionEvent.ACTION_UP using object animation . You need to have the position of the destination.
private void animate() { Path path = new Path(); path.moveTo(destinationX, destinationY); path.lineTo(destinationX, destinationY); ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mButton, View.X, View.Y, path); objectAnimator.setDuration(duration); objectAnimator.setInterpolator(new LinearInterpolator()); objectAnimator.start(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With