在Android中滑动以取消动画

我想在我的应用程序中使用幻灯片取消动画,例如whatsapp.

首先,当我按住录制按钮时,它将开始录制.这部分工作得很好.

其次,当我将手指朝后方向移动到垃圾桶时,然后“文本视图幻灯片取消”应该向后滑动并且录制应该暂停.在某一点之后我将执行垃圾桶打开动画.但是,如果我向前滑动,如果向前滑动则应将文本视图设置在其原始位置,并且应再次播放录音.

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

我也从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) {


                }

在Android中滑动以取消动画

解决方法:

尝试使用此代码即可.

    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;
            }
        });
    }
上一篇:超简单Fragment使用dispatchTouchEvent(Activity把分发触摸事件给Fragment)+ 超简单Activity点击空白处关闭软键盘除EditText和发送按钮


下一篇:Android多点触控获取错误的指针和/或XY值