0

If i want to add animation on each item of ListView with some delay, i use LayoutAnimationControllerand specify the delay. But the order of animation here can be only NORMAL,REVERSE or RANDOM.

I am working on an animation where suppose the rows of ListView are 1,2,3,4,5. Then when i touch on row 3, the animation should go from row3->row2-> row1. In the docs, its mentioned that we should override

protected int getTransformedIndex (LayoutAnimationController.AnimationParameters params)

for custom ordering but i am not getting what value to return from this function and how to compute the custom ordering in this case?

Is there any other way this animation can be acheived?

1 Answer 1

2

Custom ordering can be done like this.

public class CustomAnimController extends LayoutAnimationController {

    private float mDelay;
    int mMiddlePosition;
    private View mView;
    private Context mContext;

    public CustomAnimController(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomAnimController(Animation animation) {
        super(animation);
    }

    public CustomAnimController(Context context,Animation animation, float delay) {
        super(animation, delay);
        mDelay=delay;
        mContext=context;
    }

    @Override
    protected long getDelayForView (View view){

        ViewGroup.LayoutParams params=view.getLayoutParams();
        LayoutAnimationController.AnimationParameters animationParameters=params.layoutAnimationParameters;

        int index=getTransformedIndex(animationParameters);

        return (long)(index*mDelay*200);

       //return 0;

    }


    @Override
    protected int getTransformedIndex (LayoutAnimationController.AnimationParameters params){

        int index=params.index;


        if(index==mMiddlePosition){

            return 0;
        }

        for(int i=1;i<20;i++){

            if(index==mMiddlePosition-i || index==mMiddlePosition+i){
                return i;

            }
        }

        return 0;


    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.