Listview Item Animation In Android

Velmurugan Murugesan
Sep 19 · 2 min read

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

Before start, checkout my other post on listview:

Edittext In Listview Android Example

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

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.

Image for post
Image for post
Animation 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

Image for post
Image for post
Image for post
Image for post

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store