2017-02-08 1 views
0

私はViewを持っています。これにRotateAnimationを追加しました。それは完全に動作しています。私が持っている唯一の質問は、あらゆる角度の変化を聞く方法があるということです。私は、私がAnimationListenerを追加し、次のリスナーを使用することができますRotateAnimation:すべての角度変更を聞く

rotateAnimation.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 
    }); 

を知っているし、また、私は、ビューの角度を取得するためにView.getRotation()を使用することができます。しかし、アプリの機能は、ユーザーが選択した環境設定から計算された時間を変更します。

私が探しているのは、あらゆる角度の変化を聞くことができるリスナーです。 何かのように、onRotateAngleChange(int currentAngle)。 私が使用できるそのような方法や回避策に関する指針は大きな助けになるでしょう。

よろしくお願いいたします。

EDIT:最終ヒント/コードです。 @yakobomのポインタのおかげで。

rotateAnimation = new RotateAnimation(fromDegrees, toDegrees){ 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
      super.applyTransformation(interpolatedTime, t); 
      float degrees = fromDegrees + ((toDegrees - fromDegrees) * interpolatedTime); 
      //Do what you want to do with your angle here. 
     } 
    }; 

答えて

1

をすべてを行う必要がapplyTransformationを実装している、何か李KEこの:

RotateAnimation rotateAnim = new RotateAnimation (...) { 
       @Override 
       public void applyTransformation(float interpolatedTime, Transformation t)    
       { 
         super.applyTransformation(interpolatedTime, t); 

         <your code here> 
       } 
+0

ねえ、リアルタイムの角度をどこから得ることができるのか詳しく教えてください。私は 'interpolatedTime'や' t'をどういう意味ですか?私はそれを探しましたが、何も見つかりませんでした。 –

+0

ありがとうございました。あなたが何を意味するのかを理解するために、Rotate AnimationのJavaコードを調べなければなりませんでした。 (Y)。 –

+0

よかった、うまくいけばうれしいよ。 – yakobom

0

あなたはAPI 19以降をターゲットにしている場合は、アニメーションを使用することができますまたObjectAnimator

ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotation", initialValue, finalValue); 
animator.setDuration(duration); 
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
     @Override 
     public void onAnimationUpdate(ValueAnimator valueAnimator) { 
      currentRotation = valueAnimator.getAnimatedValue("rotation"); 
      //do something 
     } 
    }); 

を使用して同じ結果を得ることができますしかし、それはRotationAnimationの更新リスナーを追加することはできませんキットカットでのAPIは以下のように、これは非常に簡単にするために追加しました:

view.animate().rotationBy(finalValue - initalValue).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
     @Override 
     public void onAnimationUpdate(ValueAnimator valueAnimator) { 
      currentRotation = valueAnimator.getAnimatedValue("rotation"); 
      //do something 
     } 
    }); 
+0

ねえ、私はLog.d( "YO"、valueAnimator.getAnimatedValue( "回転")のtoString()。) 'を追加;' '//がdomething'一部を行うが、それはなかったですでアニメーション中に値をロギングする。さらに、ObjectAnimatorでビューの一端を修正する方法を知っていますか?RotateAnimationでピボットを設定することができました。 –

+0

ねえ、お返事ありがとうございますが、@ yakobomの答えはもっと重要でした。 –

関連する問題