MainActivity is as follows:
Package CN. testscrollview; import android. OS. bundle; import android. view. motionevent; import android. view. view; import android. view. view. ontouchlistener; import android. widget. scrollview; import android. app. activity;/*** demo Description: * listens to scrollview slides to the top and bottom ** Note: * 1 mscrollview. getchildat (0 ). getmeasuredheight () indicates the height occupied by scrollview. the height of the scrollview content. A part of the content is usually visible only after sliding. The height of this part is also included in * mscrollview. getchildat (0 ). ** 2 view in getmeasuredheight. getscrolly indicates: * The height at the top of the scrollview that has been slid out ** 3 view. getheight () indicates the visible height of * scrollview **/public class mainactivity extends activity {private scrollview mscrollview; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); Init ();} private void Init () {mscrollview = (scrollview) findviewbyid (R. id. scrollview); mscrollview. setontouchlistener (New touchlistenerimpl ();} private class touchlistenerimpl implements ontouchlistener {@ overridepublic Boolean ontouch (view, motionevent) {Switch (motionevent. getaction () {Case motionevent. action_down: break; Case motionevent. action_move: int scrolly = view. getscrolly (); int Height = view. getheight (); int scrollviewmeasuredheight = mscrollview. getchildat (0 ). getmeasuredheight (); If (scrolly = 0) {system. out. println ("slide to the top view. getscrolly () = "+ scrolly);} If (scrolly + height) = scrollviewmeasuredheight) {system. out. println ("slide to the bottom scrolly =" + scrolly); system. out. println ("sliding to the bottom height =" + height); system. out. println ("sliding to the bottom of scrollviewmeasuredheight =" + scrollviewmeasuredheight);} break; default: break;} return false ;}};}
Main. xml is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ScrollView android:id="@+id/scrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world"/> </ScrollView></RelativeLayout>