graphics - Android: Moving a View with onTouch has definite lag -
i'm coming learning curve on android, @ moment working on user interface details. 1 of basic things trying moving around on screen finger. seems fundamental thing do.
i started relativelayout (rl), created 100x100 view has contrasting background color (intentionally simple, low graphics overhead) , add view rl. using view.setx , view.sety can move view around fine.
next, added ontouchlistener view , used resulting .getrawx , .getrawy values move view. works - there definite lag. expected view stay right under finger trails behind. it's noticeable.
edit: here's ontouch code:
public boolean ontouch(view v,motionevent event) { boolean bexitvalue = true; int iaction; iaction = event.getactionmasked(); if (motionevent.action_move == iaction) { v.setx(event.getrawx()); v.sety(event.getrawy()); } else if (motionevent.action_down != iaction) { bexitvalue = false; } return(bexitvalue); }
i've tightened ontouch method as possible keep efficient - i'm using primitives, no objects being created, etc. - didn't help. further things i've tried:
reducing size of view 100x100 50x50, dropping number of pixels must redrawn 75%. no improvement.
overrode view.ontouchevent instead of registering ontouchlistener. no improvement.
added android:hardwareaccelerated="true" manifest. no improvement.
it seems counterintuitive, tried inserting thread.sleep() in motionevent handler, based on various comments found online suggested doing so. no improvement, got predictable slowdown sleep value increased!
used motionevent.getx , .gety instead of "raw" versions. got interleaved pairs of coordinates appeared absolute , relative, making view jumpy, abandoned research when current question resolved.
i'm running code on new google nexus 7, don't think hardware starving throughput.
moving object on screen finger fundamental. i've got missing something, because no 1 ship commercial code slow reaction time i'm seeing.
i've scanned here, , google can find, no solutions yet. in advance guidance!
you don't have issue code, have implemented simple drag , have same symptoms you, device related issue, each device has it's own lag when calls on touch. if enable show touch (ics , above) on device see lags little comparing real input. , not 1 experiencing issue. there lot of discussions this.
edit: if bothered this, here suggestion, noticeable on high speed input, try measuring speed of input , anticipate next point, brings issues sudden changes of direction, , concept needs lot of thinking through.
hope helps , enjoy work.
Comments
Post a Comment