LayoutAnimationController 中的自定义排序

Custom ordering in LayoutAnimationController

如果我想在 ListView 的每个项目上添加一些延迟的动画,我使用 LayoutAnimationController 并指定延迟。但是这里的动画顺序只能是NORMAL,REVERSE或者RANDOM。

我正在制作一个动画,假设 ListView 的行是 1、2、3、4、5。然后当我触摸第 3 行时,动画应该从第 3 行->第 2 行->第 1 行开始。 在文档中,它提到我们应该覆盖

protected int getTransformedIndex (LayoutAnimationController.AnimationParameters params)

用于自定义排序,但我没有从该函数中得到 return 的值,以及在这种情况下如何计算自定义排序?

还有其他方法可以实现这个动画吗?

自定义排序可以这样完成。

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;


    }

}