2016-01-07 17 views
0

我有佈局,在底部我有view.layout與列表視圖,我想要使用手勢上下。如用戶點擊視圖,並採取它應該上去,如果他向下滑動,那麼應該往下走。像我們的抽屜左,右這樣,我頂想底部,說屏幕的30%應涵蓋...使用OnTouchListener方向向上和向下佈局

public class OnSwipeTouchListener implements View.OnTouchListener { 

private final GestureDetector gestureDetector; 

public OnSwipeTouchListener (Context ctx){ 
    gestureDetector = new GestureDetector(ctx, new GestureListener()); 
} 



@Override 
public boolean onTouch(View v, MotionEvent event) { 
    return gestureDetector.onTouchEvent(event); 
} 

private final class GestureListener extends GestureDetector.SimpleOnGestureListener { 

    private static final int SWIPE_THRESHOLD = 100; 
    private static final int SWIPE_VELOCITY_THRESHOLD = 100; 

    @Override 
    public boolean onDown(MotionEvent e) { 
     return true; 
    } 

    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
     boolean result = false; 
     try { 
      float diffY = e2.getY() - e1.getY(); 
      float diffX = e2.getX() - e1.getX(); 
      if (Math.abs(diffX) > Math.abs(diffY)) { 
       if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { 
        if (diffX > 0) { 
         onSwipeRight(); 
        } else { 
         onSwipeLeft(); 
        } 
       } 
       result = true; 
      } 
      else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { 
       if (diffY > 0) { 
        onSwipeBottom(); 
       } else { 
        onSwipeTop(); 
       } 
      } 
      result = true; 

     } catch (Exception exception) { 
      exception.printStackTrace(); 
     } 
     return result; 
    } 
} 

public void onSwipeRight() { 
} 

public void onSwipeLeft() { 
} 

public void onSwipeTop() { 
} 

public void onSwipeBottom() { 
} 

}

這個代碼給用戶剛做下來等..但我怎麼可以滑動查看..我想做萬歲手不動畫coz動畫時,他按下它會上去不像他的手去

回答

0

您可以使用Umano向上滑動面板進行工作。

檢查this

+0

部分來自lib任何其他因爲它有太多的方法 – bob