2017-05-05 5 views
0

다음 기능을 통해 동적으로 뷰에 뷰를 추가하고 있습니다. 이 함수를 사용하여 5 개의 뷰를 생성하고 있습니다. 이것은 잘 작동합니다. 내 문제는 애니메이션을 뷰에 적용 할 때 모든 뷰가 애니메이션으로 표시되는 경우입니다. 첫 번째로 생성 된 뷰를 애니메이션화하고 두 번째로 애니메이션을 만들고 싶습니다. 액티비티가 시작될 때마다 5 개의 뷰가 모두 페이드 인됩니다. 이미 setStartOffset을 시도했지만 작동하지 않습니다. 어떻게해야합니까? 뷰의 동적 추가 (MainActivity.java)에 대한동적으로 추가 된 뷰의 시퀀스 애니메이션

기능 :

public void addViewInActivity() { 
    container.addView(addView); 

    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in); 

    final long startOffset = 1000; 
    animation.setStartOffset(startOffset); 

    addView.startAnimation(animation); 
} 

fade_in.xml

<?xml version="1.0" encoding="UTF-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <alpha 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:duration="500" 
     android:repeatCount="0" /> 
</set> 
+0

는 각 뷰에 IDS를 할당 않았다 도와 드릴까요? –

+0

각보기에는 하나의 ID 만 있지만 각보기에 고유 한 태그가 할당되었습니다. –

+0

각보기에 고유 한 ID를 설정하려고 시도하고 첫 번째 ID 애니메이션을 시작하고 애니메이션 끝 수신기에서 두 번째 애니메이션을 시작합니다. –

답변

1

사용이 당신이

private long startOffset = 1000; 

public void addViewInActivity() { 
    container.addView(addView); 

    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in); 
    startOffset += 500; 
    animation.setStartOffset(startOffset); 

    addView.startAnimation(animation); 
} 
+0

나는 그것을 시도하고 완벽하게 작동했습니다. 빠른 답장을 보내 주셔서 감사합니다. 당신의 방법은 매우 간단합니다. –

0

당신은 컨테이너에 애니메이션을 적용 할 수 있습니다. 다음 예제를 고려하십시오.

이것은 ParentLayout입니다. 여기서 다중 뷰를 동적으로 추가합니다. 다음

<LinearLayout 
android:id="@+id/layoutStatus" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layoutAnimation="@anim/list_layout_animation" 
android:orientation="horizontal" 
android:padding="10.0dip" /> 

list_layout_animation

<?xml version="1.0" encoding="utf-8"?> 
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" 
    android:animation="@anim/slide_in_right" 
    android:delay="0.5" /> 

이며,이는 .. 당신은 갈 준비가 slide_in_right

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="400" 
    android:fillAfter="true" 
    android:fromXDelta="-100.0%" 
    android:toXDelta="0.0%" /> 

그게 전부입니다!

관련 문제