简体   繁体   English

如果第二个动画开始,像Flip动画这样的Gmail会被中断

[英]Gmail like Flip animation get's interrupted if second animation starts

I have implemented an Android listview with flip checkboxes (GMail style) as shown here: http://techiedreams.com/gmail-like-flip-animated-multi-selection-list-view-with-action-mode/ 我已经实现了一个带有翻转复选框(GMail风格)的Android列表视图,如下所示: http//techiedreams.com/gmail-like-flip-animated-multi-selection-list-view-with-action-mode/

The problem I have (even in the source code example): If there are multiple items I click/check in a fast sequence, the previous animation stops and will be restared. 我遇到的问题(即使在源代码示例中):如果有多个项目我单击/检查一个快速序列,前一个动画停止并将被重新设置。 In other words, the previous animation does not finish and is interrupted by the second one. 换句话说,前一个动画没有完成并被第二个动画中断。

Simple download the source code and try it on your own. 简单下载源代码并自行尝试。 In comparisson to gmail all animations, no matter how fast I'm clicking, are performed from the start to the end. 在comparisson中gmail所有动画,无论我点击的速度有多快,都是从开始到结束进行的。

I can't find the piece of code in the demo source code to change this behaviour. 我无法在演示源代码中找到这段代码来改变这种行为。

Any hints? 任何提示?

Thanks in advance :) 提前致谢 :)

This is the closest I could get to Gmail's flip animation: 这是我最接近Gmail的翻转动画:

In the getView() method (I'm using contextual action mode): 在getView()方法中(我正在使用上下文操作模式):

        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()));

                            }
                        }
                    }
                }
                                       );

Then the animateRow() method: 然后是animateRow()方法:

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);

        }
    }
}

I hope it helps.. :) 我希望它有帮助.. :)

Now you can forget that method to flip a view, since I've developed a new library FlipView fully customizable, this is exactly what you want. 现在你可以忘记翻转视图的方法,因为我开发了一个完全可自定义的新库FlipView ,这正是你想要的。 You will be able to swap any kind of views and layouts with any kind of animation you desire. 您可以使用任何类型的动画交换任何类型的视图和布局。

Please have a look. 请看一看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM