1

I am trying to do swipe from both side in Listview but now i only able to do from right side, but i want to do swipe from both left and right please can any one tell me how to do that.

private void swipe(int dis) {
    if (dis > mMenuView.getWidth()) {
        dis = mMenuView.getWidth();
    }
    if (dis < 0) {
        dis = 0;
    }

    mContentView.layout(-dis, mContentView.getTop(), mContentView.getWidth() - dis, getMeasuredHeight());

    mMenuView.layout(mContentView.getWidth() - dis, mMenuView.getTop(),
            mContentView.getWidth() + mMenuView.getWidth() - dis,
            mMenuView.getBottom());
}

/onSwipe Function/

    public boolean onSwipe(MotionEvent event) {
         mGestureDetector.onTouchEvent(event);

      switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mDownX = (int) event.getX();
        isFling = false;
        break;
      case MotionEvent.ACTION_MOVE:
        // Log.i("byz", "downX = " + mDownX + ", moveX = " + event.getX());
        int dis = (int) (mDownX - event.getX());
        if (state == STATE_OPEN) {
            dis += mMenuView.getWidth();
        }
        swipe(dis);
        break;
        case MotionEvent.ACTION_UP:
        if (isFling
                || (mDownX - event.getX()) > (mMenuView.getWidth() / 1.5)) {
            // open
            smoothOpenMenu();
        } else {
            // close
            smoothCloseMenu();
            return false;
        }
        break;
    }
    return true;
}

Please go through the above code and suggest me some solution.

  • when is swipe() function called ? on swipe ? and what is "dis" ? could you please elaborate ? – Pranjal Sahu May 30 '15 at 16:36
  • sure i will do that please wait... – Anshuman Patnaik May 30 '15 at 16:37
  • I think use the class given in this link to detect right or left swipe. http://stackoverflow.com/questions/17520750/list-view-item-swipe-left-and-swipe-right Basically as per my understanding "dis" is the displacement. And mContentVIew.layout sets the left, top, right, bottom coordinates of the of mContentView. SO based on left or right use -dis and dis. You can try this solution. Also to check it please print the value of dis. – Pranjal Sahu May 30 '15 at 16:50
  • hey i have updated my post please go through it... – Anshuman Patnaik May 30 '15 at 17:11
  • just replace -dis by dis for right. I think that should work. dis denotes the distance by which you have swiped. Let me know the result. – Pranjal Sahu May 30 '15 at 17:55
  • no dude it's not working...not coming accurate result.. – Anshuman Patnaik May 30 '15 at 18:00
  • ok do one thing in the line `int dis = Math.abs((int) (mDownX - event.getX()));` And then if it is left swipe use -dis and if it right then use dis. – Pranjal Sahu May 30 '15 at 18:23
  • For the right code will be this right - mContentView.layout(dis, mContentView.getTop(), mContentView.getWidth() - dis, getMeasuredHeight()); – Anshuman Patnaik May 30 '15 at 18:28
  • `mContentView.layout(dis, mContentView.getTop(), mContentView.getWidth() + dis, getMeasuredHeight()); mMenuView.layout(mContentView.getWidth() + dis, mMenuView.getTop(), mContentView.getWidth() + mMenuView.getWidth() + dis, mMenuView.getBottom());` It would be helpful if you could share some screenshots. – Pranjal Sahu May 30 '15 at 18:39
  • i am not having that much of reputation to post images, but i have uploaded the images please go through it. http://i.stack.imgur.com/yWNXl.png, http://i.stack.imgur.com/yWNXl.png – Anshuman Patnaik May 30 '15 at 18:56
  • first image is for right to left and second one is left to right but it's not working properly. – Anshuman Patnaik May 30 '15 at 18:57

0 Answers0