【发布时间】:2013-10-31 16:04:35
【问题描述】:
我一直在尝试编写将图像旋转到特定角度的活动方法。 旋转有效,但问题是该方法每秒左右调用一次,但仅在前几次旋转。 在某个时刻,动画图像只是静止不动,即使动画正在设置并以不同的值开始!它假设移动图像,就像前几次一样。
private void animateNeedle(final float sfAngle)
{
final View viewNeedle = findViewById(R.id.needle);
final RotateAnimation needleAnimation;
RotateAnimation anim;
anim = new RotateAnimation( 0,
sfAngle,
m_nNeedleWidth / 2,
m_nNeedleHeight);
anim.setDuration(200);
anim.setFillAfter(true);
viewNeedle.setAnimation(anim);
anim.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(final Animation animation)
{
viewNeedle.clearAnimation();
}
@Override
public void onAnimationRepeat(final Animation animation)
{
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(final Animation animation)
{
// TODO Auto-generated method stub
}
});
anim.start();
findViewById(android.R.id.content).postInvalidate();
}
我做错了什么? 我确保该函数在动画期间不会被调用两次,但它没有帮助。
【问题讨论】:
-
你从哪里调用函数?
-
从一个事件中,确切地说是接收到的音频样本,但这种情况每秒只发生一次,以检查它是否是与线程相关的问题。
-
您确定传递的
sfAngle始终非零吗? -
你是从 UI 线程开始动画的吗?
-
您是否尝试在方法签名中添加同步关键字以确保它不是多线程问题? (view needle 设置新的动画对象,而另一个线程调用 .clearAnimation())
标签: android multithreading animation views