android - Synchronized scrolling of multiple custom views -


i've got custom view, draws scale , handles touch event (horizontall scroll of scale). drawing part:

@override public void ondraw(canvas canvas){     startingpoint = mainpoint;     counter = 0;     int = 0;      while (startingpoint <= scalewidth) {         if(i % 4 == 0) {             size = scaleheight / 4;              if (counter < 24) {                 counter = counter + 1;             } else {                 counter = 1;             }              string c = integer.tostring(counter);             canvas.drawtext(c, startingpoint, endpoint - (size + 20), textpaint);          } else {             if(i % 2 == 0) {                 size = scaleheight / 8;             } else {                 size = scaleheight / 16;             }         }          if(startingpoint >= closest) {             //метки шкалы             canvas.drawline(startingpoint, endpoint - size, startingpoint, endpoint, rulerpaint);          }          startingpoint = startingpoint + pxmm;          = + 1;       } } 

and touchevent:

public boolean ontouchevent(motionevent event) {     switch (event.getaction()) {         case motionevent.action_down:             float x = event.getx();             prevx = x;             system.out.println(x);             break;         case motionevent.action_move:             float z = event.getx();             float dist = z - prevx;             mainpoint = prevsp + dist;             closest = mainpoint - ((int)(mainpoint / pxmm)) * pxmm;             break;         case motionevent.action_up:             float y = event.getx();             prevsp = mainpoint;             break;     }      invalidate();      return true; } 

in activity_main.xml paste 2 copies of view:

<linearlayout 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" android:orientation="vertical" android:gravity="center|top">  <net.manualuser.calibr.timescale     android:id="@+id/my_scale"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@android:color/white" />  <net.manualuser.calibr.timescale     android:id="@+id/my_scale1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@android:color/white" /> 

should synchronize these 2 views when scroll either scale 1 moves simultaneously. if i'm correct need set ontouchlistener custom views in mainactivity:

timescale defscale = (timescale)findviewbyid(r.id.my_scale); timescale defscale1 = (timescale)findviewbyid(r.id.my_scale1); defscale.setontouchlistener(this); defscale1.setontouchlistener(this); 

and write code synchronize them in ontouch method (in mainactivity). have idea how do it?

to working need pass event both of views in ontouch in mainactivity:

public boolean ontouch(view v, motionevent event){     defscale.ontouchevent(event);     defscale1.ontouchevent(event);     return false; } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -