Android 滑动取消动画

Slide to cancel Animation in Android

我想要一个幻灯片来取消动画,就像我的应用程序中的 whatsapp。

首先,当我按住录制按钮时,它会开始录制。这部分效果不错。

其次,当我在已经点击的情况下将手指向后移动到垃圾桶时,"Text View Slide to cancel" 应该向后滑动并且录制应该暂停。在某个点之后我将执行垃圾桶打开动画。但是如果当我向前滑动时向后滑动,那么文本视图应该设置在它的原始位置并且录音应该再次播放。

我的问题:如何准确滑动文本视图,我没有得到任何帮助。

我也从这里得到了帮助https://github.com/sarathnk/Audio,但我无法达到预期的结果。

这是我的 Java 代码:

holdtoRecord = (ImageView)  findViewById(R.id.hold);
slider = (TextView) findViewById(R.id.slide);

holdtoRecord.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    // start recording.
                    mVideoView.pause();
                    onHold();

                    return true;

                }

                if (event.getAction() == MotionEvent.ACTION_UP) {
                    // Stop recording and save file


                    mVideoView.start();
                    offHold();

                    return true;
                }


                if (event.getAction() == MotionEvent.ACTION_MOVE) {


                }

尝试使用此代码,它会起作用。

    int xPos_terminal = 100;
    int xPos_DragInitial = 0;


hold.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {


                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    // start recording.

                    xPos_DragInitial = (int) motionEvent.getX();
                    xPos_SliderOriginal = (int) slider.getX();

                    int xPos_Trash = (int) trash_cap.getX();

                    Log.e("original", String.valueOf(xPos_Trash));
                    return true;

                }

                if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    return true;

                }



                if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {


                     int xPos_current = (int) motionEvent.getX();


                    //Handling of SlideToCancel View
                    String slideToViewMsg = "";
                    if(xPos_current < xPos_DragInitial)
                    {
                        //LEFT DIRECTION
                        Log.e("----- LEFT DIRECTION --","S");
                        if(xPos_SliderOriginal > (xPos_terminal))
                        {
                            slideToViewMsg = "Animate SlideToCancel view to Reduce its X";
                             lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                            int newXOfSlider = (int) slider.getX();
                            newXOfSlider -= 2;
                            lp.setMargins(newXOfSlider, (int) slider.getY(), 0, 0);
                            slider.setLayoutParams(lp);
                        }
                        else
                        {
                            slideToViewMsg = "Donot Animate SlideToCancel view";
                        }
                    }
                    else
                    {
                        //RIGHT DIRECTION
                        Log.e("---- RIGHT DIRECTION --","r");
                        if((int)slider.getX() < xPos_SliderOriginal)
                        {
                            slideToViewMsg = "Animate SlideToCancel view to increase X";
                            int newXOfSlider = (int) slider.getX();
                            newXOfSlider += 2;
                            lp.setMargins(newXOfSlider, (int) slider.getY(), 0, 0);
                            slider.setLayoutParams(lp);
                        }
                        else
                        {
                            slideToViewMsg = "Donot Animate SlideToCancel View";
                        }
                    }

                    Log.e("x",slideToViewMsg);
                    //Handling of Delet button  
                    if (xPos_current < (xPos_terminal))
                    {
                        //Animate Delete button to open


                    }
                    else
                    {
                        //Animate Delet Button To Close

                    }

                    //chnage xPosInitial to xPosCurrent to get actual direction
                    xPos_DragInitial = xPos_current;
                    return true;

                }

                return false;
            }
        });
    }