2016-04-10 15 views
0

xとyのどちらの方向にも回転させずに回転させたい矢印のドロアブルがあります。 さらに説明すると、固定点または円形のAndroidプログレスバーについてボールが回転しているとします。 さらに、ドロアブルは、クリックされると-180度、再びクリックされると180度回転します。矢印のドローラブルを中心に回転させる方法

これはプログラムで実行できますか?

更新 ジェイソンWihardjaの答えから、私はこれを達成することができました:とにかく、私はアニメーションの建物の繰り返しを避けることができ

@Override 
     public void onClick(View v) { 


      if (v.getId() == imageButton.getId()) { 
       int visibilty =newsBody.getVisibility(); 
       if (visibilty == View.VISIBLE) { 
        Animation animation = new RotateAnimation(180.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
        animation.setInterpolator(new DecelerateInterpolator()); 
        animation.setRepeatCount(0); 
        animation.setFillAfter(true); 
        animation.setDuration(300); 
        imageButton.startAnimation(animation); 
        newsBody.setVisibility(View.GONE); 

       } else { 
        Animation animation = new RotateAnimation(0.0f, 180.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
        animation.setInterpolator(new DecelerateInterpolator()); 
        animation.setRepeatCount(0); 
        animation.setFillAfter(true); 
        animation.setDuration(300); 
        imageButton.startAnimation(animation); 
        newsBody.setVisibility(View.VISIBLE); 
       } 
      } 
     } 

をしかし、あるのでしょうか?一度構築するだけで、クリックごとに度を切り替えるようにします。

+0

「android.graphics.drawable.RotateDrawable」を使用 – pskink

+0

恐らく重複:http://stackoverflow.com/questions/3496036/rotate-bitmap-on-android-canvas – user1676075

+0

@ user1676075矢印は、 res/drawableフォルダにあり、ImageButtonの 'src'として使用しています。 – X09

答えて

0

これを行うにはRotateAnimationクラスを使用できます。

RotateAnimation rotateAnimation = new RotateAnimation(180.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
rotateAnimation.setInterpolator(new DecelerateInterpolator()); 
rotateAnimation.setRepeatCount(0); 
rotateAnimation.setDuration(animationDuration); 
rotateAnimation.setFillAfter(true); 
arrowImageView.startAnimation(rotateAnimation); 

角度のパラメータを反転するだけです。

+0

ありがとう、質問を更新しました。 – X09

+0

xmlバージョンでコードを置き換えることができます。しかし、そうしても、2つのアニメーションファイルを作成する必要があります –

関連する問題