当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Animation only starts after speech recognition has completed

问题描述:

I'm writing an app that uses android's speech recognition.

In my RecognitionListener I have something like this:

@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB)

public void onRmsChanged(float rmsdB)

{

if(mSpeakButtonBorder == null) mSpeakButtonBorder = (ImageView) findViewById(R.id.SpeakButtonBorder);

// Should continue growing in size each time onRmsChanged is called.

Animation animation = new ScaleAnimation(mSpeakButtonBorder.getScaleX(), mSpeakButtonBorder.getScaleX() + 0.1f, mSpeakButtonBorder.getScaleY(), mSpeakButtonBorder.getScaleY() + 0.1f);

animation.setDuration(1000);

animation.setFillAfter(true);

mSpeakButtonBorder.startAnimation(animation);

}

Why does the animation only start after recognition has returned with a result?

网友答案:

OnRmsChanged() will normally keep getting called while Speech Recognition is going on. Since you've set fillAfter to true and the duration of the animation to 1000 ms.

So you're infact, starting a new animation in every call to OnRmsChanged() (called every few ms or even more frequently) before the animation actually finishes. Now the problem is that the transformations applied do NOT apply to the View, they just transform the way it's drawn.

I believe the animation is still getting applied. Just that the transformation is too minute to notice, one because of the duration being too small and another because the target scale factor is very small.

So when you use the supposedly current scaleX next time, it actually results in same value as the original (which is 1.0).

You may use an ObjectAnimator to animate, which actually applies the transformations to the View or calculate the relative the input scale values yourself and then feed to ScaleAnimation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: