简体   繁体   中英

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?

I solved using LayoutAnimationController.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM