Listview item animation in android

This post regarding implementing animation effect for the listview items. By using AnimationUtils, I have implemented this animations for the listview items.

Steps to create listview item animation

  • Create the listview
  • Create view for the listview item
  • Add animations in anim folder
  • Create the animation and set the animation in the listview adapter

Related Post

customize listview android

Edittext in listview android example

Swipelistview in android


Step 1 – Create the listview

Create the listview and then create simple ArrayList to set in the listview, add values into the ArrayList.

ArrayList<String> items=new  ArrayList<>();
listView=(ListView)findViewById(R.id.listview);
for(int i=0;i<100;i++){
items.add("Item "+i);
}

Step 2 – Create view for the listview item

Create a view to set the items into the listview using the baseAdapter.

LayoutInflater inflater = getLayoutInflater();
view = inflater.inflate(R.layout.list_adapter, parent, false);
TextView itemName=(TextView)view.findViewById(R.id.itemName);
itemName.setText(items.get(position));

Step 3 – Add animations in anim folder

Create anim folder under the res folder, and add the needed xml files.

Anim Folder Location

Step 4 – Create the animation and set the animation in the listview adapter

Finally, Create the animation and set the animation in the listview adapter view.

Animation animation = null;
animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.wave);
animation.setDuration(200);
view.startAnimation(animation);
animation = null;

Screenshots

Listview item animation
Listview item animation
Download

4 thoughts on - Listview item animation in android

Leave a Reply

Your email address will not be published. Required fields are marked *