2017-06-01 40 views
1

我打算給佈局動畫項目的ListView,我之前使用了android:layoutAnimationAndroid:如何編寫layoutAnimation而不是xml

<LinearLayout 
     ... 
     android:layoutAnimation="@anim/layout_anim" /> 

// ../res/anim 
<layoutAnimation 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:animation="@anim/slide_up" /> 

我試着在適配器中給出以下代碼。

public View getView(int position, View convertView, ViewGroup parent) { 
     ... 
     Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up); 
     v.startAnimation(animation); 

     return v; 
} 

它可以工作,但slide_up動畫是通過完整活動的級別實現的,而不是項目級別。它從活動的底部出現。最初它應該從項目的底部出現。

我錯了什麼?

回答

3

我解決了使用LayoutAnimationController。

LinearLayout layout = (LinearLayout) lineView.findViewById(R.id.linearLayout); 
LayoutAnimationController anim = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_anim); 
layout.setLayoutAnimation(anim);