android采集中动画,Android:如何在AnimationDrawable中获取当前帧

我有同样的问题,尝试过每个函数,并且没有成功,因为像’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’…)的函数.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值