Scroroller for Android (3) -- controls are moved across the screen (simple to use scroroller) and androidscroroller

Source: Internet
Author: User

Scroroller for Android (3) -- controls are moved across the screen (simple to use scroroller) and androidscroroller
MainActivity is as follows:

Package cc.cn; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. app. activity;/*** Demo Description: * Scroller use example -- let the control Pan across the screen ** reference: * http://blog.csdn.net/c_weibin/article/details/7438323 * Thank you very much ** note: * 1 in the layout, set cc.cn. the width of the Listener Control is set to "fill_parent" * to facilitate observation of sliding effect */public class MainActivity extends Activity {private Button mButton; private LinearLayoutSubClass success; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mLinearLayoutSubClass = (LinearLayoutSubClass) findViewById (R. id. linearLayoutSubClass); mButton = (Button) findViewById (R. id. button); mButton. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View view) {mLinearLayoutSubClass. beginScroll ();}});}}

LinearLayoutSubClass is as follows:
Package cc.cn; import android. content. context; import android. util. attributeSet; import android. widget. linearLayout; import android. widget. scroller;/*** API Note: ** 1 // first, the start position of the two parameters, the offset of the four scrolling parameters, and the duration of the fifth parameter * startScroll (int startX, int startY, int dx, int dy, int duration) ** 2 // during startScroll () method execution, the computescroloffset () * method will always return true during the duration time, however, after the animation is executed, false is returned. * computescroloffset () ** 3 when ontouch (), invalidate (), or postInvalidate () is executed, this method is called * computeScroll () **/public class LinearLayoutSubClass extends LinearLayout {private Scroller mScroller; private boolean flag = true; public LinearLayoutSubClass (Context context) {super (context);} public LinearLayoutSubClass (Context context Context, attributeSet attrs) {super (context, attrs); // you can also use this constructor to input an interpolator // mScroller = new Scroller (context, interpolator ); mScroller = new Scroller (context) ;}@ Overridepublic void computeScroll () {super. computeScroll (); if (mScroller. computescroloffset () {scrollTo (mScroller. getCurrX (), 0); // make it call computeScroll () again until the sliding ends, that is, it does not meet the if condition postInvalidate () ;}} public void beginScroll () {if (flag) {mScroller. startScroll (0, 0,-2500, 0, 2500); flag = false;} else {mscroroller. startScroll (0, 0, 0, 0, 1500); flag = true;} // call invalidate (); so that it calls computeScroll () invalidate ();}}

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"> <Button android: id = "@ + id/button" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: text = "sliding after clicking"/> <cc.cn. linearLayoutSubClass android: id = "@ + id/linearLayoutSubClass" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_centerVertical = "true"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: background = "# ff1100" android: text = "test Scroller"/> </cc.cn. linearLayoutSubClass> </RelativeLayout>


Scroroller problems for android

In the first image, do I call repaint when I flip the page to the left?
 

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.