2014-12-01 3 views
0

애니메이션을 적용하려는 여러 TextView가 있습니다. 같은 애니메이션을 사용하고 싶지만 각 TextView마다 다른 시간에 시작합니다. 검색했지만 찾지 못했습니다. setStartOffset 시도했지만 지시대로 사용하지 않는 것 같습니다. 누군가 나를 도울 수 있니? 이 내 코드입니다 : 내가 요소에 대해 서로 다른 애니메이션을 만들어다른 요소에서 다른 시간에 동일한 애니메이션 사용

TranslateAnimation animation = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f, 
    Animation.ABSOLUTE, -1500.0f, Animation.ABSOLUTE, 0.0f); 
    animation.setDuration(3000); 
    tvNumero1.startAnimation(animation); 

    //this fails: 
    animation.setStartOffset(300); 
    tvNumero2.startAnimation(animation); 
+0

두 개의 애니메이션 개체를 각각 하나씩 정의 해 보았습니까? 안 드 로이드가 이미 사용중인 오프셋을 제공하기 때문에 Handler 접근법은이를 과소 평가할 수 있습니다. – Toguard

답변

3

, 양자 택일로, 당신은 XML 자원에서 animaiton를 사용할 수 있습니다. 여기 코드는 : 또는

//First Animation 
TranslateAnimation animation = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f, 
    Animation.ABSOLUTE, -1500.0f, Animation.ABSOLUTE, 0.0f); 
animation.setDuration(3000); 
tvNumero1.startAnimation(animation); 

//Second Animation 
TranslateAnimation animation2 = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f, 
    Animation.ABSOLUTE, -1500.0f, Animation.ABSOLUTE, 0.0f); 
animation2.setDuration(3000); 
animation2.setStartOffset(300); 
tvNumero2.startAnimation(animation2); 

, XML 파일에 애니메이션을 정의 할 수 있습니다 : 여기

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="3000" 
    android:fromYDelta="-1500" 
    android:toYDelta="0" > 

</translate> 

되는 XML에 대한 코드 :

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.text_move); 
tvNumero1.startAnimation(animation); 

Animation animation2 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.text_move); 
animation2.setStartOffset(300); 
tvNumero2.startAnimation(animation2); 

이전 코드는 기다리고있어 보인다는 오프셋에 대해 전체 애니메이션을 시작한 후 3 초로 변경하고 시작하는 데 3 초가 걸립니다.

+0

Toguard 정말 고마워요. 그가 찾고 있던 것. 코드의 선택은 생각했지만, 내가 필요로하는 많은 동등한 애니메이션 (요소의 비)이기 때문에 코드를 적게 사용하는 것이 필요했습니다. XML 코드의 선택은 완벽합니다. 시간 내 주셔서 대단히 감사합니다 –

관련 문제