Android Smooth Vertical Scroll On Touch
I have a view that's inside a frame layout. I am tracking the ontouch event for the view and I want the view to scroll vertically in a smooth scrolling fashion up and down as I mov
Solution 1:
try this one (you can add some checks at the top/bottom or fling as well):
classScrollingTextViewextendsTextView {
private GestureDetector mDetector;
publicScrollingTextView(Context context) {
super(context);
StringBuildersb=newStringBuilder();
for (inti=0; i < 30; i++) {
sb.append("Line #").append(i).append("\n");
}
setTextSize(24);
setText(sb);
setTextColor(0xffeeeeee);
mDetector = newGestureDetector(mListener);
}
privateOnGestureListenermListener=newSimpleOnGestureListener() {
@OverridepublicbooleanonScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
scrollBy(0, (int) distanceY);
returntrue;
}
};
@OverridepublicbooleanonTouchEvent(MotionEvent event) {
mDetector.onTouchEvent(event);
returntrue;
}
}
to test it add the following in Activity.onCreate:
Viewv=newScrollingTextView(this);
setContentView(v);
Post a Comment for "Android Smooth Vertical Scroll On Touch"