Notice
Recent Posts
Recent Comments
올해는 머신러닝이다.
[팁]HorizontalScrollView랑 scrollview 같이 사용하기 본문
출처 : 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 |