Simultaneous Translations on Android -


i'm trying several translations simultaneously on android.

i have 2 or more buttons on layout (all same size), , when press 1 want others move out of screen.

i've done test app try implement behaviour.

on i've set listener on click of 1 button test, like:

button.setonclicklistener(new view.onclicklistener() {      public void onclick(view view) {         button tomove = (button) findviewbyid(r.id.button_test2);         button tomove2 = (button) findviewbyid(r.id.button_test3);          animationset set = new animationset(true);          translateanimation anim = new translateanimation(0, -tomove           .getwidth(), 0, 0);         anim.setfillafter(true);         anim.setduration(1000);          tomove.setanimation(anim);         tomove2.setanimation(anim);          set.addanimation(anim);          set.startnow();     } 

the view:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="fill_parent"     android:layout_height="fill_parent">      <button android:id="@+id/button_test" android:layout_width="200px"         android:layout_height="50px" android:text="@string/hello" />      <button android:id="@+id/button_test2" android:layout_width="200px"         android:layout_height="50px" android:text="@string/hello"/>      <button android:id="@+id/button_test3" android:layout_width="200px"         android:layout_height="50px" android:text="@string/hello"/>  </linearlayout> 

the thing 2 buttons start animation, 1 after other. i've read due getdelayforview() returns different delays of each. there way move 2 or more buttons simultaneously?

google not helpful :-\

issue:

it seems setanimation acutally start animation , asynchronously. there might lock on setting animation second view. there must dispatcher because setting animation buttons in different order not affect fact bottom 1 faster.

the solution prevent hypothetical lock creating 2 individual animations.

code:

public void onclick(view view) {     button tomove = (button) findviewbyid(r.id.button_test2);     button tomove2 = (button) findviewbyid(r.id.button_test3);      translateanimation anim = new translateanimation(0, -tomove             .getwidth(), 0, 0);     anim.setfillafter(true);     anim.setduration(1000);      translateanimation anim2 = new translateanimation(0, -tomove             .getwidth(), 0, 0);     anim2.setfillafter(true);     anim2.setduration(1000);      //there 1 more trick      tomove.setanimation(anim);     tomove2.setanimation(anim2); } 

note:

in //there 1 more trick, add following code ensure move together. there still must lag of 1 millisecond or so.

long time =animationutils.currentanimationtimemillis();  //this invalidate needed in new android versions @ least in order view refreshed. tomove.invalidate();  tomove2.invalidate(); anim.setstarttime(time); anim2.setstarttime(time); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -