I want to run this type of animations in background when this method is call then start immediately without any delay and without freezing ui or main thread.
when is call this moethod then play music, start animation and after complete animation view deletion and creation process is running then i saw delay and ui freezing.
public void stackToStack(ArrayList<Card> subString, int targetX, boolean fromUndo) {
System.out.println("Size ==> " + subString.size());
Stacks targetStack = mainStacks.get(targetX);
ArrayList<Float> getYPositions = getYPosition(targetStack,false);
if (!fromUndo) {
Music.move();
}
for (int i = 0; i < subString.size(); i++){
float xPos = (targetX * cardWidth);
float yPos = getYPositions.get(targetStack.indexOf(subString.get(i),-1,1));
CardView cardView = mainRelative.findViewWithTag(subString.get(i).getCard());
cardView.setZ(1);
TranslateAnimation animation = new TranslateAnimation(0, xPos - cardView.getX(), 0, yPos - cardView.getY());
animation.setDuration(animationSpeed);
animation.setFillAfter(true);
cardView.startAnimation(animation);
int finalI = i;
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (finalI == subString.size()-1) {
StacksView stacksView = new StacksView();
stacksView.addViews();
isNewClick = true;
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
New contributor
Human is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.