package zm.scroolview;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
public class MainActivity extends Activity{
private ScrollView sl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sl = (ScrollView) findViewById(R.id.sl);
sl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int scrollY=view.getScrollY();
int height=view.getHeight();
int scrollViewMeasuredHeight=sl.getChildAt(0).getMeasuredHeight();
if(scrollY==0){
System.out.println("滑动到了顶端 getScrollY()="+scrollY);
}
if((scrollY+height)==scrollViewMeasuredHeight){
System.out.println("滑动到了底部 scrollY="+scrollY);
System.out.println("滑动到了底部 height="+height);
System.out.println("滑动到了底部 scrollViewMeasuredHeight="+scrollViewMeasuredHeight);
}
break;
default:
break;
}
return false;
}
});
}
}