2013-02-12 1 views
20

그래서 동일한 회전 사양을 사용하여 한 번에 여러보기를 동시에 회전하고 싶습니다. 문제는 어떤 이유로 회전이 두 번째 요소에서 다르게 작동한다는 것입니다. 분명히 이것은 애니메이션 객체가 실제로 두 줄의 코드 사이에서 상태를 변경하는 것과 관련이 있습니다. 분명히 난 그냥 별도의 애니메이션 객체를 생성하고 그것을 적용되지만하나의 애니메이션을 동시에 여러보기에 적용하십시오.

회전합니다 첫 번째보기 제대로 쉬운 방법 (I 약 15 전망이)가 같은 느낌 수 :

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

가 모두 제대로 회전

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"> 

아이디어가 있습니까? 그래서

+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); 
    } 
} 

해킹,하지만 난 그게 내가 '모든 것 같아요 지금 할 수 m

+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 개의보기에 적용하려고합니다. –

관련 문제