«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

올해는 머신러닝이다.

[팁]HorizontalScrollView랑 scrollview 같이 사용하기 본문

Android/Tip&Tech

[팁]HorizontalScrollView랑 scrollview 같이 사용하기

행복한 수지아빠 2011. 11. 30. 20:03

출처 : http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling

public
class CustomScrollView extends ScrollView {
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;

public CustomScrollView(Context context, AttributeSet attrs) {
   
super(context, attrs);
    gestureDetector
= new GestureDetector(new YScrollDetector());
    setFadingEdgeLength
(0);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
   
return super.onTouchEvent(ev);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
   
//Call super first because it does some hidden motion event handling
   
boolean result = super.onInterceptTouchEvent(ev);
   
//Now see if we are scrolling vertically with the custom gesture detector
   
if (gestureDetector.onTouchEvent(ev)) {
       
return result;
   
}
   
//If not scrolling vertically (more y than x), don't hijack the event.
   
else {
       
return false;
   
}
}

// Return false if we're scrolling in the x direction  
class YScrollDetector extends SimpleOnGestureListener {
   
@Override
   
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
       
try {
           
if (Math.abs(distanceY) > Math.abs(distanceX)) {
               
return true;
           
} else {
               
return false;
           
}
       
} catch (Exception e) {
           
// nothing
       
}
       
return false;
   
}
}

'Android > Tip&Tech' 카테고리의 다른 글

[팁]AutoCompleteTextView랑 DB랑 싱크시키기  (3) 2011.12.05
[팁]ActionBar 커스텀하기  (0) 2011.12.01
Intent 개념 총정리  (2) 2011.11.30
웹뷰 키보드 위치조절(webview)  (0) 2011.11.29
SQL function(함수) 모음  (2) 2011.11.23