Answer the question
In order to leave comments, you need to log in
How to implement the launch of animation in another thread with a delay in the execution of the code of the main thread ???
How to implement the launch of animation in another thread with a delay in the execution of the code of the main thread ???
Implemented auto moving cards (imageview) to the stack. It is necessary through animation to move the object once per second into the stack, while delaying the code of the main thread.
Answer the question
In order to leave comments, you need to log in
When moving an object, make the main thread sleep() for the specified time, or queue the execution of the thread
And what for still a separate flow if the main all the same will sleep? Do everything in the main thread and mustache, or am I missing something?
launched in this way: in the main class I registered
TestJoinMethod1 t1;
t1=new TestJoinMethod1();
// вызов
t1.baseitem(fn, animX, animY, kart);
t1.start();
try{
t1.join();
}catch(Exception e){System.out.println(e);}
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class TestJoinMethod1 extends Thread {
Klondike klondike;
int fn;
int animX, animY;
ImageView kart[] = new ImageView[52];
void baseitem(int fn2, int animX2, int animY2, ImageView[] karts)
{
fn=fn2;
animX=animX2;
animY=animY2;
for (int i = 0; i < karts.length; i++)
{
kart[i]=karts[i];
}
}
public void run(){
System.out.println("running...");
try{
Thread.sleep(1000);
}catch(Exception e){System.out.println(e);}
kart[fn].setVisibility(View.INVISIBLE);
TranslateAnimation anim0 = new TranslateAnimation(kart[fn].getX(), 0, kart[fn].getY(), 0);
anim0.setDuration(1000);
anim0.setFillAfter(true);
kart[fn].bringToFront();
kart[fn].setX(animX);
kart[fn].setY(animY);
kart[fn].startAnimation(anim0);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question