I spend several hours by trying to animate view slide UP, slide Down based on the finger direction. I am able to fire onFling event on the custom view and get direction of the finger movement using
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Logger.d("onFling "+ velocityY);
if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
Logger.d("Bottom to top");
slideView(velocityY, e1, e2, Constants.Global.MOVE_BOTTOM_TOP);
return false; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
Logger.d("Top to bottom");
slideView(velocityY, e1, e2, Constants.Global.MOVE_TOP_BOTTOM);
return false; // Top to bottom
}
return false;
}
I tried to do fling animation using the FlingAnimation:
FlingAnimation flingAnimation = new FlingAnimation(viewGroup, DynamicAnimation.TRANSLATION_Y); // moves the view on the x-axis
// derive the pixelPerSecond with start velocity value
float pixelPerSecond = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, motionEvent1.getY(), getResources().getDisplayMetrics());
flingAnimation
.setStartVelocity(pixelPerSecond)
.setMinValue(motionEvent1.getRawY())
.setMaxValue(toYDelta)
.setFriction(0.8f)
.start();
or using the TranslateAnimation or SlideOutUpAnimator from the following library:
https://github.com/daimajia/AndroidViewAnimations
Unfortunately, the slideout animation of the view is still not working correctly.
The view can be positioned in Y-axis using the processing in onScroll event:
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Logger.d("onScroll distanceX: "+distanceX+" distanceY: "+distanceY);
params.y = initialY + (int) (e2.getRawY() - initialTouchY);
params.x = 0;
windowManager.updateViewLayout(view, params);
return false;
}
OnScroll positioning works great, but I still have a problem to animate slideout to bottom or top. I think that is based on the wrong processing of root view which should be positioned too.
Could someone experienced with animations on the views provide some example how should be slideout animation on Y-axis done in the right way, please?
Many thanks for any advice.