Answer the question
In order to leave comments, you need to log in
How to implement swipe animation in android?
Hello!
We implemented swipe animation in our application: i.e. you can move the element with your finger and it disappears off the screen.
For animation, we catch the touch points of the finger on the screen and (when a certain area is reached) we start the animation of going beyond the given element.
However, this method has a drawback: the animation does not depend on the speed of the finger movement. With a sharp jerk with your finger, it will not work if it does not reach the border of the animation start.
Do you need to calculate the speed of your finger and set your own conditions or are there ready-made solutions?
Please provide links to examples or documentation.
Answer the question
In order to leave comments, you need to log in
Notice the onFling event. It returns the movement speeds velocityX and velocityY:
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Toast.makeText(getApplicationContext(), "Fling Gesture", 100).show(); return true;
}
If you use a RecyclerView (and it's recommended to switch to it from a ListView, and it's quite easy), then there is a great thing, ItemTouchHelper .
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
...
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
//Удалить свайпнутый элемент из списка и нотифицировать об этом ресайклер
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
...
itemTouchHelper.attachToRecyclerView(recyclerView);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question