The goal is to animate the view from one place to another, so first we need to get two points. You can do the following:
int[] screenLocation = new int[2]; textView.getLocationOnScreen(screenLocation); int startX = screenLocation[0]; int startY = screenLocation[1]; int[] screenLocationB = new int[2]; cartView.getLocationOnScreen(screenLocationB); int endX = screenLocationB[0]; int endY = screenLocationB[1];
As soon as you have both the original location of the text field and the location you want it to end (the location of the viewer), we need to animate one point from the next two. We can do this by placing the NEW textview on the window layer or in the frame above your list.
Here we add the windows to the layer:
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.width = view.getMeasuredWidth(); layoutParams.height = view.getMeasuredHeight(); activity.addContentView(newTextView, layoutParams);
Then we set the starting position.
newTextView.setTranslationX(startX); newTextView.setTranslationY(startY);
Finally, we animate.
newTextView.animate().setDuration(300) .translationX(endX).translationY(endX).start()
source share