I have a project for which I have to display some images. Even if the Gallery widget is deprecated, it seems to be the best choice, since I have not so much time to spend on it.
I would like to mimic Android's photo gallery and deleting an image when swiping it up or down (see the screenshots below). I saw in another SO question that we can detect vertical swipings (see the code below), but I would like to move the image during the movement, as in Android's photo gallery.
Moreover, there is something really great in their app: the swipe is progressive, so we have to move the image to the extreme borders (up or down) to remove the image. If we want to cancel the removing, we simply have to drop our finger from the image.
How could I implement this feature?
public class CustomGallery extends Gallery
{
[...]
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (Math.abs(velocityX) > Math.abs(velocityY))
// Moving horizontally
else
// Moving vertically
return super.onFling(e1, e2, velocityX, velocityY);
}
}
NB: I can also accept an answer based on HorizontalScrollView if it implements the up- or down-swiping feature and if it has center-locking.
!
I have the same situation with you, so i really hope there is someone who can help. I am using ViewPager to implement the horizontal scroll, and add onTouchListener on each item to detect the swipe up and down, i know it's not a good way, but it works!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.