java - How to perform animations on android sdk? -
im working on animation android application. purpose of app animate sort/search algorithms. having problems using objectanimator, because cant swap 2 elements. here relevant code:
public void swapnodes(textview node1, textview node2, int animationspeed) { //switching leftmost rightmost if (node1.getx() > node2.getx()) { textview temp = node1; node1 = node2; node2 = temp; } handler h = new handler(); h.postdelayed(moveuprunnable(node1, 150, 0, 1000), ithrun*1000); ++ithrun; h.postdelayed(movedownrunnable(node2, 150, 0, 1000), ithrun*1000); ++ithrun; float distance = node2.getx() - node1.getx(); h.postdelayed(moverightrunnable(node1, distance, 0, 1000), ithrun*1000); ++ithrun; h.postdelayed(moveleftrunnable(node2, distance, 0, 1000), ithrun*1000); ++ithrun; h.postdelayed(movedownrunnable(node1, 150, 0, 1000), ithrun*1000); ++ithrun; h.postdelayed(moveuprunnable(node2, 150, 0, 1000), ithrun*1000); ++ithrun; } public void movedown (final textview n, float distance, int timedelay, int duration) { objectanimator downwards = objectanimator.offloat(n, "translationy", n.gettranslationy() + distance); down.setstartdelay(timedelay); down.setduration(duration); down.start(); } public runnable moverightrunnable(final textview n, final float distance, final int timedelay, final int duration) { runnable r = new runnable() { public void run() { moveright(n,distance,timedelay,duration); } }; homecoming r; } public void moveright (final textview n, float distance, int timedelay, int duration) { objectanimator right = objectanimator.offloat(n, "translationx", n.gettranslationx() + distance); log.d("moverightx", float.tostring(n.gettranslationx())); log.d("moverighty", float.tostring(n.gettranslationy())); right.setstartdelay(timedelay); right.setduration(duration); right.start(); } public runnable moveleftrunnable(final textview n, final float distance, final int timedelay, final int duration) { runnable r = new runnable() { public void run() { moveleft(n,distance,timedelay,duration); } }; homecoming r; } public void moveleft (final textview n, float distance, int timedelay, int duration) { objectanimator left = objectanimator.offloat(n, "translationx", n.gettranslationx() - distance); log.d("moveleftx", float.tostring(n.gettranslationx())); log.d("movelefty", float.tostring(n.gettranslationy())); left.setstartdelay(timedelay); left.setduration(duration); left.start(); } public runnable moveuprunnable(final textview n, final float distance, final int timedelay, final int duration) { runnable r = new runnable() { public void run() { moveup(n,distance,timedelay,duration); } }; homecoming r; } public void moveup (final textview n, float distance, int timedelay, int duration) { objectanimator = objectanimator.offloat(n, "translationy", n.gettranslationy() - distance); up.setstartdelay(timedelay); up.setduration(duration); up.start(); } java android algorithm animation objectanimator
No comments:
Post a Comment