2

I'm using ViewDragHelper to slide a view to a new location, and I'm trying to use viewDragHelper.smoothSlideViewTo(dragView, x, y). The question is: How do I get a notification after the slide animation is complete? I'm looking for a way to listen to the slide animation events (especially something like onSlideAnimationComplete() ). Any idea folks?

private boolean smoothSlideTo(float slideOffset) {
    final int topBound = getPaddingTop();
    int x = (int) (slideOffset * (getWidth() - transformer.getMinWidthPlusMarginRight()));
    int y = (int) (topBound + slideOffset * getVerticalDragRange());
    if (viewDragHelper.smoothSlideViewTo(dragView, x, y)) {
        ViewCompat.postInvalidateOnAnimation(this);
        return true;
    }
    return false;
}
yongsunCN
  • 736
  • 7
  • 18

1 Answers1

0

It seems viewdraghelper doesn't have listener or callback when doing animation, but you can solve it by implement onViewDragStateChanged and judge through its state, like this:

    @Override
    public void onViewDragStateChanged(int state) {
        if (state == 0) {
            if (settleDestX == contentView.getLeft() && swipeOverListener != null) {
                swipeOverListener.onSwipeOver(settlePosition);
            }
        }
    }

state==1 implies dragging, state==2 implies scrolling, state==0 implies idle.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38