Android learns Scroller (two)--viewgroup transfer Scrollto ()

Source: Internet
Author: User

Mainactivity such as the following:
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 (for example, Xxxlayout here) calls Scrollto (by) * Its content (that is, all its child view) will move. * * Reference information: * 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 is faster and more blunt. * The Scroller class can be used to optimize the sliding process of the Scrollto (by) (). * This class of source code the first sentence of this class encapsulates scrolling. * The purpose of this class is indicated: The sliding process is encapsulated. * In the following demo sample, you will learn the use of scroller.   */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 such as the following:

<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>


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Android learns Scroller (two)--viewgroup transfer Scrollto ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.