java - How to force View to recalculate it's position after changing parent -


it has been days since have problem.

this reformulation of this question considering behavior describe on this answer. please, note question states less specific case, , answer useful many different scenarios.

i'm moving 1 chip left point right point, , writing original , new coordinates:

backgammon beforebackgammon after

so failing:

public void ontouch(view view) {     int[] aux = new int[2];      //get chip     view movingchip = findviewbyid(r.id.c1);     //write it's coordinates     movingchip.getlocationonscreen(aux);     ((textview)findviewbyid(r.id.p1t1)).settext("(" + aux[0] + "," + aux[1] + ")");     //move     ((linearlayout)findviewbyid(r.id.p1)).removeview(movingchip);     ((linearlayout)findviewbyid(r.id.p2)).addview(movingchip);     movingchip.requestlayout();//#### adding didn't solve      //write it's coordinates     movingchip.getlocationonscreen(aux);     ((textview)findviewbyid(r.id.p2t4)).settext("(" + aux[0] + "," + aux[1] + ")"); } 

when coordinates second time, coordinates of view if positioned in new parent @ same place in old one

so, new top, left, bottom, right etc... not being calculated @ point. on other hand, views displayed properly, job getting done @ point. how force calculation happen ?

i need way, because i'll want trigger transition animation

i suggest using onlayoutchangelistener capture chip movements. of course, have attach listeners outside ontouch event

    chip.addonlayoutchangelistener(new onlayoutchangelistener()     {         @override         public void onlayoutchange(view v, int left, int top, int right, int bottom, int oldleft, int oldtop, int oldright, int oldbottom)         {          }     }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -