Java 类似Gmail的翻转动画get';如果第二个动画开始,则会中断

Java 类似Gmail的翻转动画get';如果第二个动画开始,则会中断,java,android,animation,Java,Android,Animation,我已经实现了一个带有翻转复选框(GMail风格)的Android listview,如下所示: 我遇到的问题(甚至在源代码示例中):如果在快速序列中单击/检查多个项目,则上一个动画将停止并重新启动。换句话说,上一个动画没有完成,被第二个动画打断 简单地下载源代码并自己尝试。与gmail相比,无论我点击的速度有多快,所有的动画都是从头到尾执行的 我在演示源代码中找不到更改此行为的代码片段 有什么提示吗 提前感谢:)这是我能找到的最接近Gmail flip动画: 在getView()方法中(我使用上

我已经实现了一个带有翻转复选框(GMail风格)的Android listview,如下所示:

我遇到的问题(甚至在源代码示例中):如果在快速序列中单击/检查多个项目,则上一个动画将停止并重新启动。换句话说,上一个动画没有完成,被第二个动画打断

简单地下载源代码并自己尝试。与gmail相比,无论我点击的速度有多快,所有的动画都是从头到尾执行的

我在演示源代码中找不到更改此行为的代码片段

有什么提示吗


提前感谢:)

这是我能找到的最接近Gmail flip动画:

在getView()方法中(我使用上下文操作模式):

holder.check.setOnClickListener(
新建视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
if(mActionMode==null){
选中=新SparseBooleanArray(alllists.size());
mActionMode=((活动)getActivity()).startActionMode(mActionModeCallback);
动画师(位置);
选中。放置(位置,正确);
mActionMode.setTitle(“1”);
mActionMode.getMenu().getItem(0).setVisible(true);
}否则{
动画师(位置);
如果(选中。获取(位置)){
选中。放置(位置,错误);
如果(选中。indexOfValue(true)<0){
mActionMode.finish();
}否则{
setTitle(String.valueOf(getCheckedCount());
}
}否则{
选中。放置(位置,正确);
setTitle(String.valueOf(getCheckedCount());
}
}
}
}
);
然后使用animateRow()方法:

private void animateRow(最终int位置){

如果(position>=listView.getFirstVisiblePosition()&&position现在您可以忘记翻转视图的方法,因为我开发了一个完全可自定义的新库,这正是您想要的。您将能够使用所需的任何动画交换任何类型的视图和布局

请看一看

        holder.check.setOnClickListener(
                new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (mActionMode == null) {
                            checked = new SparseBooleanArray(alllists.size());
                            mActionMode = ((Activity) getActivity()).startActionMode(mActionModeCallback);
                            animateRow(position);
                            checked.put(position, true);
                            mActionMode.setTitle("1");
                            mActionMode.getMenu().getItem(0).setVisible(true);
                        } else {
                            animateRow(position);
                            if (checked.get(position)) {
                                checked.put(position, false);
                                if (checked.indexOfValue(true) < 0) {
                                    mActionMode.finish();

                                } else {
                                    mActionMode.setTitle(String.valueOf(getCheckedCount()));

                                }
                            } else {
                                checked.put(position, true);
                                mActionMode.setTitle(String.valueOf(getCheckedCount()));

                            }
                        }
                    }
                }
                                       );
private void animateRow(final int position) {
    if (position >= listView.getFirstVisiblePosition() && position <= listView.getLastVisiblePosition()) {
        Log.i("animateRow", String.valueOf(position));
        ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 1, Animation.RELATIVE_TO_SELF, 0.5f, 0, 0);
        anim.setDuration(150);
        anim.setRepeatCount(1);
        anim.setRepeatMode(Animation.REVERSE);

        viewa = listView.getChildAt(position - listView.getFirstVisiblePosition());
        final Button chkButton = (Button) viewa.findViewById(R.id.logo);

        if (checked.get(position)) {
            anim.setAnimationListener(
                    new AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            Log.i("anim" + position, "Start");
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                            Log.i("anim" + position, "Repeat" + animation.getRepeatCount());
                            viewa.setBackgroundResource(R.color.row_background);
                            chkButton.setBackgroundResource(R.color.button_background);
                            chkButton.setText(String.valueOf(alllists.get(position).itemsCount));
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            Log.i("anim" + position, "END");

                        }
                    }
                                     );
            chkButton.startAnimation(anim);

        } else {

            anim.setAnimationListener(
                    new AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            Log.i("anim" + position, "Start");
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                            viewa.setBackgroundResource(R.color.checked_row_background);
                            chkButton.setBackgroundResource(R.color.checked_button_background);
                            chkButton.setText("✓");
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            Log.i("anim" + position, "END");

                        }
                    }
                                     );
            chkButton.startAnimation(anim);

        }
    }
}