Android移动向下滑动以向上滑动视图

时间:2017-11-30 04:35:23

标签: java android android-animation slideup motionevent

我正在使用this library来使用向下滑动菜单,问题是当我想要从上到下移动手柄并想要从滑动向下更改为向上滑动时,我尝试更改变量但是不能做对

这是原始代码

/* User tapped down on screen. */
                    case MotionEvent.ACTION_DOWN:
                        // User has tapped the screen
                        yStart = event.getRawY();
                        lastY = event.getRawY();
                        currentHeight = slideDownView.getHeight();
                        break;

                    /* User is dragging finger. */
                    case MotionEvent.ACTION_MOVE:

                        // Calculate the total height change thus far.
                        float totalHeightDiff = event.getRawY() - yStart;

                        // Adjust the slide down height immediately with touch movements.
                        LayoutParams params = slideDownView.getLayoutParams();
                        params.height = (int)(currentHeight + totalHeightDiff);
                        slideDownView.setLayoutParams(params);

                        // Check and set which direction drag is moving.
                        if (event.getRawY() > lastY) {
                            directionDown = true;
                        } else {
                            directionDown = false;
                        }

                        // Set the lastY for comparison in the next ACTION_MOVE event.
                        lastY = event.getRawY();
                        break;

                    /* User lifted up finger. */
                    case MotionEvent.ACTION_CANCEL:
                    case MotionEvent.ACTION_UP:

                        /*
                         * Need to snap either up or down. Using ValueAnimator to "finish" the action. 
                         * HeightEvaluator is a custom class. 
                         * 
                         * NOTE: I'm using the nineoldandroids library for 
                         */
                        if (directionDown) {

                            // Open the sliding view.
                            int startHeight = slideDownView.getHeight(); 

                            ValueAnimator animation = ValueAnimator.ofObject(
                                    new HeightEvaluator(slideDownView),
                                    startHeight, 
                                    (int) openHeight).setDuration(300);

                            // See Table 3 for other interpolator options 
                            // - http://developer.android.com/guide/topics/graphics/prop-animation.html
                            animation.setInterpolator(new OvershootInterpolator(1));
                            animation.start();

                        } else {

                            // Close the sliding view.
                            int startHeight = slideDownView.getHeight(); 
                            ValueAnimator animation = ValueAnimator.ofObject(
                                    new HeightEvaluator(slideDownView),
                                    startHeight, 
                                    (int) closedHeight).setDuration(300);
                            animation.setInterpolator(new OvershootInterpolator(1));
                            animation.start();
                        }
                        break;

如何让它反转?所以我可以从下往上滑动?是否必须在HeightEvaluator.java

中进行更改

1 个答案:

答案 0 :(得分:0)

最后我使用BottomSheet并设置PeekHeight以使用底部的按钮创建一个slideUp,该按钮仍然可见以触发slideView