Animate each item of Listview when displaying

18,418

You can apply a android:layoutAnimation on the ListView.

  • Create your animation XML file in anim folder. For example (slide_right_in.xml):

    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:duration="400"
        android:fromXDelta="-100%"
        android:toXDelta="0%"/>
    
  • Create another animation XML file with root element layoutAnimation :(my_layout_animation.xml)

    <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:animation="@anim/slide_right_in"
        android:delay="0.5"/>
    
  • Apply it on any ViewGroup you want. For example ListView:

    <ListView
        android:layoutAnimation = "@anim/my_layout_animation"
        ... />
    
Share:
18,418

Related videos on Youtube

Adil Bhatty
Author by

Adil Bhatty

droid guy

Updated on September 13, 2022

Comments

  • Adil Bhatty
    Adil Bhatty over 1 year

    I am trying to show listview elments in a manner that each one of them animates and then become visible so after one by one they animate and get visible to user. but When I implemented the animation, its not working on individial item, but working on the whole listview :(

    public View getView(final int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
    
            LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row =layoutInflater.inflate(R.layout.categories_row, parent, false);
    
    
    
    
            tvCatName = (TextView) row.findViewById(R.id.tvCatName);
    
            tvCatName.setText(Data.alCategoriesModels.get(position).catname);
    
    
            row.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
    
                    Toasts.pop(activity, "Category id :  " + Data.alCategoriesModels.get(position).catID); 
    
                }
            });
    
    //      row.setAnimation(animation);
            row.startAnimation(animation);
    
            return row;
        }
    

    enter image description here

    How to make one by one animation on each element of list view. I am extend ArrayAdapter.

  • Adrian Cid Almaguer
    Adrian Cid Almaguer almost 9 years
    can you add some explanation?