how to make translation animation for each listview items
@user724861 has given the perfect answer!!how ever i found it's confusing where to put the code he has suggested...i put that code in my ListFragment activity as follow..
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); AnimationSet set = new AnimationSet(true); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(300); set.addAnimation(animation); /*animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 50.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(10); set.addAnimation(animation); just comment if you don't want :) */ LayoutAnimationController controller = new LayoutAnimationController( set, 0.5f); lv.setLayoutAnimation(controller); adapter = new LazyAdapter(getActivity(), numResults, nodes, tabType); setListAdapter(adapter);}
the animation of each item should not start at the same time
If you want it, you can do something like this:
layout_controller.xml:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"android:delay="30%"android:animation="@anim/scale" />
scale.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"><scale android:fromXScale="0.1" android:toXScale="1" android:fromYScale="0.1" android:toYScale="1.0" android:duration="800" android:pivotX="10%" android:pivotY="10%" android:startOffset="100" /></set>
And then in your Java after SetListAdapter() paste the following code:
LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation( this, R.anim.layout_controller);getListView().setLayoutAnimation(controller);
note that "android:delay" makes animations start with delay after previous one.