Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement google+ listview animation

I want to Implement a animation experience like google+ listview.When user slide the listview,each item that first loaded in the listview will start a animation.I attempt to add animation in getview method to animate each item,but I want to confirm whether this way is a good method and do I need to extend listview class to finish this?So please give me some advice or some examples that like google+ listview.Thanks a lot:)

like image 511
CrystalJake Avatar asked May 31 '13 02:05

CrystalJake


2 Answers

You don't need to extend ListView class.

Here is an Android library that implemented Google plus-like ListView animation.

GenericBaseAdapter.java

GPlusListAdapter.java

MainActivity.java

The way it works is, in the adapter's getView method, it animates the view if it is newly loaded.
(So, it extended Adapter, not ListView, to make an animation.)

You can also download the sample app's apk in the link in sugared-list-animations-sample

like image 108
Naetmul Avatar answered Oct 26 '22 07:10

Naetmul


Google Plus style ListViews are all the rage these days on Android because of the slick animations it displays when presenting data. When a user scrolls down, new items animate up into view, and quite frankly it looks awesome up_from_bottom.xml

   <?xml version="1.0" encoding="utf-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
    android:fromXDelta="0%" android:toXDelta="0%"
    android:fromYDelta="100%" android:toYDelta="0%"
    android:duration="400" />
   </set>

Down from Top down_from_top.xml

   <?xml version="1.0" encoding="utf-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
    android:fromXDelta="0%" android:toXDelta="0%"
    android:fromYDelta="-100%" android:toYDelta="0%"
    android:duration="400" />
    </set>

In your list adapter class

     private int lastPosition = -1;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//Load your view, populate it, etc...
      View view = ...;

    Animation animation = AnimationUtils.loadAnimation(getContext(), (position   > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
    view.startAnimation(animation);
    lastPosition = position;

    return view;
    }

copied from http://kylewbanks.com/blog/Implementing-Google-Plus-Style-ListView-Animations-on-Android

like image 31
Chaitu Avatar answered Oct 26 '22 07:10

Chaitu