我有同样的问题,尝试过每个函数,并且没有成功,因为像’getCurrentFrame()’这样的函数返回一个十六进制值,每次运行你的应用程序时都会改变,所以,我做了一些可以解决我的问题,希望解决了你的问题:
你不必试图得到帧的图像名称(‘fruits1′),而是必须得到帧的位置,将用户停止的动画置于帧’fruits2’中,因此,帧的数量是1,因为0是帧’fruits1’.你会怎么做?
// Create the animation
myImage.setBackgroundResource(R.anim.myanimation);
myAnimation = (AnimationDrawable) myImage.getBackground();
停止动画时,您可以执行以下操作:
myAnimation.stop();
// The variable that will guard the frame number
int frameNumber;
// Get the frame of the animation
Drawable currentFrame, checkFrame;
currentFrame = myAnimation.getCurrent();
// Checks the position of the frame
for (int i = 0; i < myAnimation.getNumberOfFrames(); i++) {
checkFrame = myAnimation.getFrame(i);
if (checkFrame == currentFrame) {
frameNumber = i;
break;
}
}
因此,变量’frameNumber’将保护帧的编号,在您的情况下为0,1或2.如果有很多帧,你可以使用一个数组,根据帧的数量做一个返回名称(‘fruits1’,’fruits2’…)的函数.