I
I
Ilfar2017-06-20 20:25:24
Android
Ilfar, 2017-06-20 20:25:24

Why, after moving the ImageView, does the shape not return to its original state and remains hidden forever?

Why doesn't the shape return to its original state after moving the ImageView and remain hidden forever?

OnTouchListener onTch = new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                ClipData clipData = ClipData.newPlainText("", "");
                View.DragShadowBuilder dsb = new View.DragShadowBuilder(v);
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                     Log.d(LOG_TAG, "ACTION_DOWN");
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//.N
                        Log.d(LOG_TAG, "startDragAndDrop1");
                        v.startDragAndDrop(clipData, dsb, v, 0);
                        Log.d(LOG_TAG, "startDragAndDrop2");
                    } else {
                        Log.d(LOG_TAG, "startDragAndDrop3");
                        v.startDrag(clipData, dsb, v, 0);
                        Log.d(LOG_TAG, "startDragAndDrop4");
                    }
                   v.setVisibility(View.INVISIBLE);
                    Log.d(LOG_TAG, "1234");
                    return true;
                }else {
                    return false;
                }
            }
        };


        imV.setOnTouchListener(onTch);

@Override
    public boolean onDrag(View v, DragEvent event) {
        Log.d(LOG_TAG, "12");
        int action = event.getAction();
        View view = (View) event.getLocalState();
        switch (action) {
            case DragEvent.ACTION_DRAG_STARTED:
                // do nothing
                Log.d(LOG_TAG, "12345");
                return true;
            case DragEvent.ACTION_DRAG_ENTERED:
                return true;
            case DragEvent.ACTION_DRAG_EXITED:
                Log.d(LOG_TAG, "12346");
                return true;
            case DragEvent.ACTION_DROP:
                Log.d(LOG_TAG, "12347");
               ViewGroup owner = (ViewGroup) view.getParent();
               owner.removeView(view);
               ConstraintLayout container = (ConstraintLayout) v;
            container.addView(view);
               view.setVisibility(View.VISIBLE);
                return true;
            case DragEvent.ACTION_DRAG_ENDED:
                Log.d(LOG_TAG, "12348");
                view.setVisibility(View.VISIBLE);
                return true;
            default:
                break;
        }
        return true;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question