Reputation: 2359
If i want to add animation on each item of ListView with some delay, i use LayoutAnimationController
and 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?
Upvotes: 0
Views: 340
Reputation: 2359
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;
}
}
Upvotes: 2