Igor
Igor

Reputation: 91

Android: How to code layoutAnimation instead of xml

I'm going to give layout animation to item of ListView, which I used android:layoutAnimation before.

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

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

I tried to give following codes in adapter.

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

        return v;
}

And it works but the slide_up animation is implemented by full activity's level, not the item level. It appears from bottom of the activity. Originally it should appear from the bottom of item.

What was I wrong?

Upvotes: 2

Views: 1093

Answers (1)

Igor
Igor

Reputation: 91

I solved using LayoutAnimationController.

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

Upvotes: 4

Related Questions