简体   繁体   English

Android 拖动过程中的动画 Alpha Animation 现在工作

[英]Android Animate Alpha during Drag Animation Now Working

I've added the drag functionality to a component using ViewDragHelper and I'm trying to add a fade animation to the component so that when the user touches the screen and drag it, it changes the component's alpha using an animation.我已经使用 ViewDragHelper 向组件添加了拖动功能,并且我正在尝试向组件添加渐变 animation,以便当用户触摸屏幕并拖动它时,它会使用 animation 更改组件的 alpha。 The problem is that the animation waits for the user's interaction to stop and then it applies the animation so that during the component transition, you can't see the alpha animation,问题是 animation 等待用户的交互停止,然后应用 animation 以便在组件转换期间,您看不到 alpha animation,

override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int {
        if(top < verticalRange)
            return verticalRange
        backgroundView.animate().alpha((backgroundView.alpha - 0.05).toFloat()).duration = 10
        return top
    }

The on touch Event:触摸事件:

 override fun onTouchEvent(event: MotionEvent): Boolean {
            return if (isDragEnabled && (isControlScreenLayoutTarget(event) || isMoving)) {
                viewDragHelper.processTouchEvent(event)
                true
            } else {
                super.onTouchEvent(event)
            }
        }

You should not start your animation in clampViewPositionVertical() .您不应该在clampViewPositionVertical()中启动 animation 。 That method is called to return the boundaries where the view will move, actually scroll.调用该方法以返回视图将移动的边界,实际上是滚动。

Instead you should wait until view is released, in other words, start your animation as soon as the range check is fulfilled in the onViewReleased() .相反,您应该等到视图被释放,换句话说,在onViewReleased()中完成范围检查后立即启动 animation。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM