Android dual-row sliding table (double-head not moving)

Source: Internet
Author: User

※effect


※ Usage
Package Com.cd.slidetest;import Android.os.bundle;import Android.app.activity;import android.graphics.color;import Android.view.gesturedetector;import Android.view.menu;import Android.view.motionevent;import Android.view.gesturedetector.simpleongesturelistener;import Android.widget.linearlayout;import Android.widget.linearlayout.layoutparams;import Android.widget.scrollview;public class MainActivity extends Activity implements onscrollchangedlistener{private gesturedetector Mgesturedetector = null;private Hscrollview Mitemroom = null;private ScrollView mvertical = null;private Hscrollview mtimeitem = null;private LinearLayout MContain = NULL, @SuppressWarnings ("deprecation") @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate); mgesturedetector = new Gesturedetector (Mgesturelistener); Makeitems (); Setcontentview (MContain) ;} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;} private voidMakeitems () {mitemroom = new Hscrollview (this, mgesturedetector); Mitemroom.setlistener (this); LinearLayout vlayout = new LinearLayout (this); Vlayout.setorientation (linearlayout.vertical); for (int i = 0;i < 20;i++) {LinearLayout hlayout = new LinearLayout (this ); for (int j = 0;j < 10;j++) {Textitem item = new Textitem (this); Item.settext (i*10+j + "VH"); Item.setbackgroundcolor (Col Or. Ltgray); Linearlayout.layoutparams params = new Layoutparams (100,70); Hlayout.addview (item, params);} Vlayout.addview (hlayout);} Mitemroom.addview (vlayout); mvertical = new ScrollView (this); LinearLayout hlayout = new LinearLayout (this); LinearLayout vlayout = new LinearLayout (this), vlayout.setorientation (linearlayout.vertical); for (int i = 0;i < 20;i++ {Textitem item = new Textitem (this); Item.setbackgroundcolor (Color.Blue); Item.settext (i + "V"); Linearlayout.layoutparams params = new Layoutparams (100,70); Vlayout.addview (item, params);} Hlayout.addview (vlayout); Hlayout.addview (mitemroom); Mvertical.addview (hlayout); LineArlayout tophlayout = new LinearLayout (this); Mtimeitem = new Hscrollview (this, mgesturedetector); Mtimeitem.setlistener (this); LinearLayout layout = new LinearLayout (this), for (int i = 0;i < 10;i++) {Textitem item = new Textitem (this); Item.settext ( i + "h"); Item.setbackgroundcolor (Color.green); Linearlayout.layoutparams params = new Layoutparams (100,70); Layout.addview (item,params);} Mtimeitem.addview (layout); Textitem item = new Textitem (this); Item.setbackgroundcolor (color.red); Linearlayout.layoutparams params = new Layoutparams (100,70); Tophlayout.addview (item,params); Tophlayout.addview ( Mtimeitem); mcontain = new LinearLayout (this); Mcontain.setorientation (linearlayout.vertical); Mcontain.addview ( Tophlayout); Mcontain.addview (mvertical);} Private Simpleongesturelistener Mgesturelistener = new Simpleongesturelistener () {@Overridepublic Boolean onscroll (                Motionevent E1, Motionevent e2,float Distancex, float Distancey) {if (Math.Abs (Distancex) > Math.Abs (Distancey)) { return true;} ReTurn false;}}; @Overridepublic void onscrollchanged (Hscrollview scroll, int x, int y, int oldx,int oldy) {if (scroll = = mitemroom) {Mtimeit Em.scrollto (x, y);} else if (scroll = = Mtimeitem) {mitemroom.scrollto (x, y);}}}
※
http://download.csdn.net/detail/u010785585/8062787


Android dual-row sliding table (double-head not moving)

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.