The use of ScrollView is relatively simple, by including more layout files, so that swipe up and down can browse to more content.
There are a few points to note about ScrollView.
Scrolling mode of 1,scrollview
ScrollView There are two kinds of scrolling, horizontal and vertical, generally horizontal use of relatively few. The ScrollView control is scrolled vertically by default, and if you need to scroll horizontally you only need to change the label
Horizontalscrollview, can meet the requirements
2,scrollview the scroll bar is displayed by default during scrolling, so there are two ways to hide the scroll bar:
1, via label settings: android:scrollbars= "None"
2, set by code: Sethorizontalscrollbareenable (False); setvertivalscrollbarenable (false);
Common methods of 3,scrollview:
1,getscrolly ()-----Returns the distance of the scroll bar sliding
2,getmeasureheight ()------Returns the total height of the ScrollView, that is, the distance of the scroll + the width of the screen
3,getheight ()-------Returns the height of the displayed scroll
The difference between 4,scrollto and Scrollby
1,scrollto: From the starting position of the scroll as a reference, the distance to scroll
2,scrollby: From the current position of the scroll as a reference, the distance to scroll
Public classMainactivityextendsActivityImplementsview.onclicklistener{PrivateTextView TextView; PrivateScrollView ScrollView; PrivateButton up; PrivateButton down; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView=(TextView) Findviewbyid (R.id.textview); ScrollView=(ScrollView) Findviewbyid (R.id.scroll); Textview.settext (R.string.text); up=(Button) Findviewbyid (R.id.button); down=(Button) Findviewbyid (R.id.button2); Scrollview.setontouchlistener (NewView.ontouchlistener () {@Override Public BooleanOnTouch (View V, motionevent event) {Switch(Event.getaction ()) { Casemotionevent.action_move:{if(Scrollview.getscaley () <=0) {android.util.log.i ("Main", "Top"); } if(scrollview.getmeasuredheight () = = Scrollview.getheight () +Scrollview.getscaley ()) {ANDROID.UTIL.LOG.I ("Main", "bottom"); } Break; } } return false; } }); } @Override Public voidOnClick (View v) {Switch(V.getid ()) { Caser.id.button:{Scrollview.scrollby (0,-30); Break; } Caser.id.button2:{Scrollview.scrollby (0,30); Break; } } }}
The ScrollView layout file is as follows:
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" > <LinearLayout android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" > <Button android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Top"Android:id= "@+id/button"/> <Button android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Down"Android:id= "@+id/button2"/> </LinearLayout> <ScrollView Android:id= "@+id/scroll"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:scrollbars= "None" > <TextView Android:id= "@+id/textview"Android:text= "@string/hello_world" android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/> </ScrollView></LinearLayout>
The use of Android learning ScrollView