2017-06-01 4 views
1

私はListViewの項目にレイアウトアニメーションを与えます。これは前にandroid:layoutAnimationを使用しました。Android:xmlの代わりにlayoutAnimationをコーディングする方法

<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); 
関連する問題