drag and drop - Layout flicker when dragging view in its MotionEvent.ACTION_MOVE android -
here picture of i'm trying do:
so, want resize single cell while dragging resize anchors (black quads) imageviews. attached custom ontouchlistener them next in motionevent.action_move:
- calculate drag offset
- set cell height/width based on offset
- reposition anchor point changing it's layout params
the outcome of cell resizes there king of flicker, more shaking left/right or up/down, small offset.
my guess problem comes when catches move event, manualy change position of anchor , then, when catches move event again doesn't handle change well...or something
i have idea put invisible imageviews under each anchor , resize based on movement not move anchor while draging. when relese it, lines coresponding visible anchor. more hacking solution :)
and finally, anubody know why happening?
edit: here code i'm handlign move event:
float dragy = event.getrawy() - resizepreviouspositiony; linearlayout.layoutparams componentparams = (linearlayout.layoutparams)selectedcomponent.layout.getlayoutparams(); linearlayout parrent = (linearlayout)selectedcomponent.layout.getparent(); view topsibling = parrent.getchildat(parrent.indexofchild(selectedcomponent.layout) - 1); linearlayout.layoutparams topsiblingparams = (linearlayout.layoutparams)topsibling.getlayoutparams(); if(dragy > 0 && selectedcomponent.layout.getheight() > 100 || dragy < 0 && topsibling.getheight() > 100) { componentparams.height = selectedcomponent.layout.getheight() - (int)dragy; topsiblingparams.height = topsibling.getheight() + (int)dragy; //bottomsiblingparams.height = bottomsibling.getheight(); selectedcomponent.layout.setlayoutparams(componentparams); repositionresizeanchors(selectedcomponent); } resizepreviouspositiony = event.getrawy();
and here reposition it:
if(((linearlayout)viewholder.layout.getparent()).getorientation() == linearlayout.vertical) { leftmargin = ((linearlayout)viewholder.layout.getparent()).getleft() + viewholder.layout.getleft() + viewholder.layout.getwidth()/2; } else { leftmargin = viewholder.layout.getleft() + viewholder.layout.getwidth()/2; } topmargin = viewholder.layout.gettop(); params = (relativelayout.layoutparams)resizetop.getlayoutparams(); params.leftmargin = leftmargin - dptopx(resizeanchorradius/2); params.topmargin = topmargin - dptopx(resizeanchorradius/2); resizetop.setlayoutparams(params);
Comments
Post a Comment