2

ObjectAnimator を使用して、株価表示に似たテキスト ビューでテキストを翻訳しています。ボタンを押すとティッカーを一時停止したい。ただし、アニメーター オブジェクトで cancel()/end() を呼び出しているにもかかわらず、ティッカーはアニメーションの最後まで動き続けます。

また、AnimatorListerner#onAnimCancel() で、基になる textView のすべてのアニメーションを明示的にクリアしようとしました。ただし、基になる textView はアニメーションに関連付けられていないようです。

誰かが何がうまくいかないかについて指摘できれば素晴らしいでしょう。

以下のコードの関連セクション。

anim = ObjectAnimator.ofFloat(mTextViewTicker, "TranslationX", 0, -mSomeValue);
anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationCancel(Animator animation) {
            Log.d(TAG,"Animation Pause invoked");
            super.onAnimationCancel(animation);
        }

        public void onAnimationEnd(Animator animation) {
            Log.d(TAG,"Animation Ended");
            ((View)((ObjectAnimator)animation).getTarget()).setTranslationX(anim.getAnimatedFraction());
        }
    });
anim.start();

public void stopScroll() {
   anim.cancel();
}

stopScroll() は、アクティビティのボタン クリックから呼び出されます。

4

0 に答える 0