Get the current frame in a Frame Animation
I need to check the current frame in a Frame Animated ImageView, but I don't see a way how. I cannot find a method for getting the current frame, and I can't get the current image of the Imageview with getImageResource() because the resource is the current frame of the stopped animation, not the image it's self.
Any idea what I could do to find what the current frame is?
EDIT: The solution ended up meaning writing my own Frame animation code:
To start the animation, call downDown();
To stop the Animation, set go = false;
The boolean 'go' , the string 'most_recent', and the handler 'mHandlerDown' are declared globally.
mHandler = new Handler();
private void downDown(){
if(go ==true){
Runnable updateTask = new Runnable() {
public void run() {
ImageView lid = (ImageVie开发者_高级运维w)findViewById(R.id.lid); // the Imageview that will be animated
if (most_recent =="l1"){ //this loop checks the most recent frame updates with the next
lid.setImageResource(R.drawable.l2);
most_recent="l2";
} else if (most_recent =="l2"){
lid.setImageResource(R.drawable.l3);
most_recent="l3";
} else if (most_recent =="l3"){
lid.setImageResource(R.drawable.l4);
most_recent="l4";
} else if (most_recent =="l4"){
lid.setImageResource(R.drawable.l5);
most_recent="l5";
} else if (most_recent =="l5"){
lid.setImageResource(R.drawable.l6);
most_recent="l6";
} else if (most_recent =="l6"){
lid.setImageResource(R.drawable.l7);
most_recent="l7";
} else if (most_recent =="l7"){
lid.setImageResource(R.drawable.l8);
most_recent="l8";
} else if (most_recent =="l8"){
lid.setImageResource(R.drawable.l9);
most_recent="l9";
} else if (most_recent =="l9"){
lid.setImageResource(R.drawable.l10);
most_recent="l10";
} else if (most_recent =="l10"){
lid.setImageResource(R.drawable.l11);
most_recent="l11";
} else if (most_recent =="l11"){
lid.setImageResource(R.drawable.l12);
most_recent="l12";
}else if (most_recent == "l12"){
lid.setImageResource(R.drawable.l13);
most_recent="l13";
}
downDownCall();
}
};
mHandlerDown.removeCallbacks(updatetask);
mHandlerDown.postDelayed(updateTask, 40);
}
}
private void downDownCall(){
if(go== true){
downDown();
}
}
精彩评论