There is a LinearLayout, and on it elements TextView. A handler is assigned to each TextView element.
... new View.OnTouchListener() { int initialX = 0; int initialY = 0; static final int MAX_CLICK_DURATION = 200; long startClickTime; @Override public boolean onTouch(View v, MotionEvent event) { long clickDuration = Calendar.getInstance().getTimeInMillis() - startClickTime; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = (int) event.getX(); initialY = (int) event.getY(); startClickTime = Calendar.getInstance().getTimeInMillis(); break; case MotionEvent.ACTION_MOVE: if (clickDuration > MAX_CLICK_DURATION) { int currentX = (int) event.getX(); int currentY = (int) event.getY(); dcl.setText(String.format(Locale.getDefault(), "(%d,%d)", currentX, currentY)); } break; case MotionEvent.ACTION_UP: if (clickDuration < MAX_CLICK_DURATION) v.performClick(); break; } return true; } }); Ideally, I plan to put an element when releasing my finger, where Drag-and-drop was started in front of the element, to which it was stretched, but for now I just output the coordinates, checking the work of the Listener.
The problem is that when a finger leaves the source element, including moving to another TextView element, the handler stops working (in this “pre-debugging example”, the coordinates stop updating), and ScrollView starts running, which contains this LinearLayout with elements .
How to make the dragging possible when leaving the original element, and scrolling is carried out only when you pinch your finger on a ScrollView's free space from TextView elements? Even with a short press, you need to save OnClick TextView, but I more or less figured out this, and the line is responsible for this:
if (clickDuration < MAX_CLICK_DURATION) v.performClick(); Ps. I am aware that it would be easier to do this using the DragListView, but in this case it is impossible. LinearLayout, on which TextView's are sitting, is a part of a component that is inherited deeply in the hierarchy, and you cannot change LinearLayout to ListView, since other components of this hierarchy will collapse.