Mainactivity as follows:
Package Cc.ac;import Android.os.bundle;import Android.view.view;import android.view.view.onclicklistener;import Android.widget.button;import Android.widget.linearlayout;import android.app.activity;/** * Demo Description: * Call the Scrollto () and Scrollby () methods on ViewGroup. * * Verification Theory: * If a viewgroup (such as xxxlayout here) calls Scrollto (by) * Its content (that is, all its child view) will move. * * Reference: * 1 http://blog.csdn.net/wangjinyu501/article/details/32339379 * 2 http://blog.csdn.net/qinjuning/article/ details/7247126 * Thank you very much * * NOTE: * The use of the Scrollto (by) () method moves faster and more blunt. * The Scroller class can be used to optimize the sliding process of the Scrollto (by) (). * The first sentence of this class of source code this class encapsulates scrolling. * The purpose of this class is indicated: The sliding process is encapsulated. * In the following example, the use of scroller will be learned. */public class Mainactivity extends Activity {private LinearLayout mlinearlayout; Private Button Mbutton; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.main); init ();} private void Init () {mlinearlayout= (linearlayout) Findviewbyid (r.id.linearlayout); mbutton= (Button) Findviewbyid (R.id.button); Mbutton.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (view view) {Mlinearlayout.scrollby (-50, 0);}});}}
Main.xml 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 "> <Line Arlayout android:id= "@+id/linearlayout" android:layout_width= "fill_parent" android:layout_height= "300 Dip "android:background=" @android: Color/darker_gray "> <textview android:layout_width=" 150d IP "android:layout_height=" 50dip "android:background=" @android: Color/black "android:text= "@string/hello_world" android:textcolor= "@android: Color/white"/> </LinearLayout> <button Android:id= "@+id/button" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentbottom= "true" android:layout_centerhorizontal= "true" android:text= "button"/>& Lt;/relativelayout>