2013-02-12 11 views
20

IDは同じ回転仕様を使用して、すべて同時に一度にビューを回転させるのが好きです。問題は、何らかの理由で、回転が2番目の要素に対して異なる動作をするということです。どうやらこれはアニメーションオブジェクトが2つのコード行の間で実際に状態を変えることと関係しています。複数のビューに同時に1つのアニメーションを適用する

Animation rotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotationtoportrait); 
target.startAnimation(rotateAnim); 
lightBtn.startAnimation(rotateAnim); 

は両方とも正常に回転します:もちろん、私はちょうど

が正しくのみ最初のビューを回転(私は約15見解を持っている)別々のアニメーションオブジェクトを作成し、それを適用されますが、もっと簡単な方法があるように私は感じることができました

Animation rotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotationtoportrait); 
Animation rotateAnim2 = AnimationUtils.loadAnimation(this, R.anim.rotationtoportrait); 
target.startAnimation(rotateAnim); 
lightBtn.startAnimation(rotateAnim2); 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="-90" 
    android:toDegrees="0" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:duration="500" android:fillAfter="true"> 

Aどんなアイディアがありますか?

+1

てみてください。また、私はこれを見ることをお勧めします:http://www.youtube.com/watch?v=_UWXqFBF86U – Leandros

+0

ビデオを愛する!しかし、私がこれまでに言うことができる新しいAPIは、動画に登場する人物が何をしていたのだろうか?(少なくとも最後に) – Jameo

+1

間違ったビデオ、申し訳ありません。 ;)http://www.youtube.com/watch?v=3UbJhmkeSig – Leandros

答えて

5

だから私は、これは単に不可能ですので、私はちょうどビューのリストに同じアニメーションを適用するヘルパーメソッドを作成した推測:確かに

public void doRotations(ArrayList<View> views, int start, int end, int xprop, float xscale, int yprop, float yscale, int duration, Boolean fillAfter){ 

    for(int i = 0; i < views.size(); i++){ 
     RotateAnimation temp = new RotateAnimation(start, end, xprop, xscale, yprop, yscale); 
     temp.setDuration(duration); 
     temp.setFillAfter(fillAfter); 
     views.get(i).startAnimation(temp); 
    } 
} 

ハックが、私は、私は「すべてのthatsの推測今すぐ行うことができメートル

+0

これは実際にはアニメーションを並行して実行しますが、アニメーションが少しずつ遅れて見えるのは(あなたがアニメーションを素早くトリガーしているためです) – Mercury

7

はこのようにそれを実行します(後方互換性の使用NineOldAndroids用)の新しいアニメーションのAPIを使用する

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "y", 100f); 
arrayListObjectAnimators.add(anim); 

ObjectAnimator anim1 = ObjectAnimator.ofFloat(view, "x", 0f); 
arrayListObjectAnimators.add(anim1); 

ObjectAnimator[] objectAnimators = arrayListObjectAnimators.toArray(new ObjectAnimator[arrayListObjectAnimators.size()]); 
AnimatorSet animSetXY = new AnimatorSet(); 
animSetXY.playTogether(objectAnimators); 
animSetXY.duration(1000); 
animSetXY.start(); 
+3

これは質問に答えません。私が正しい場合は、2つのアニメーションを同じビューに適用しています。元の投稿は2つのビューに同じアニメーションを適用したい –

関連する問題