我试图添加动能'使用窗口管理器在Y轴上从屏幕顶部移动到底部(反之亦然)到所有应用程序上方显示的自定义布局。
我试着这样做:
SCROLL_Y
但以下结果无效。我尝试将值TRANSLATION_Y
更改为ACTION_MOVE
并设置自定义值范围,但没有运气。
以这种方式在case MotionEvent.ACTION_MOVE:
params.y = initialY + (int) (event.getRawY() - initialTouchY);
if(isMovingInYAxis((int) initialTouchY ,(int) event.getRawY())) {
windowManager.updateViewLayout(view, params);
animateFlingInYAxis(view);
}
break;
事件中处理操作:
setStartVelocity(2000);
我想问一下如何以正确的方式动画在Y轴上移动?
非常感谢您的任何建议。
编辑1:设置@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Logger.d("onFling");
if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
Logger.d("Bottom to top");
animateFlingInYAxis(view, "BOTTOM_TOP");
return false; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
Logger.d("Top to bottom");
animateFlingInYAxis(view, "TOP_BOTTOM");
return false; // Top to bottom
}
return false;
}
private void animateFlingInYAxis(View view, String type) {
FlingAnimation fling = new FlingAnimation(view, DynamicAnimation.TRANSLATION_Y);
if(type.equals("BOTTOM_TOP")) {
fling.setStartValue(100); //WHICH PARAMS TO PASS?
fling.setMinValue(480); //WHICH PARAMS TO PASS?
fling.setMaxValue(0); //WHICH PARAMS TO PASS?
} else{
fling.setStartValue(470);
fling.setMinValue(480);
fling.setMaxValue(0);
}
fling.setStartVelocity(2000);
fling.setFriction(0.8F);
fling.start();
似乎效果更好,但视图部分隐藏(请参见下面的屏幕截图)。
Edit2 :我在自定义视图中实现了GestureDetector.OnGestureListener,现在我能够捕捉到投掷和滚动事件。在onFling方法中,我能够识别出手势方向(TOP_BOTTOM,BOTTOM_TOP),但是我无法进行给定方向视图的动画。
ok