In android development, sliding operations are often used in custom views, and you must prevent sliding beyond the boundary. Here is a very easy way to prevent slipping out of the boundary.
Calculate the value of the left and right border X or the upper and lower border Y. If it does not exceed the screen, the left and top borders are 0, and the right and bottom borders are the width and height of the screen. Then rewrite the scrollTo method:
@Overridepublic void scrollTo(int x, int y) {
If(x>mRightOffsetX) x=mRightOffsetX;
if(x<mLeftOffsetX) x=mLeftOffsetX;
super.scrollTo(x, y);
}
No comments:
Post a Comment