ObjectAnimator 不反转

ObjectAnimator not reversing

我有一组视图可以在屏幕上向下移动并随后反转,但现在当我尝试移动 CardView 时,它会向下移动但不会向上移动。

当用户单击一个按钮时,它会提示视图集合删除 down/fade,当用户再次单击该按钮时,它们会 return。在 space 创建的 Views collection vanishing 中,一个 CardView 下拉。我有要下拉的 CardView,但是当用户单击按钮时,视图集合 return 而不是 CardView - 相反它就消失了。干杯!

MainActivity(注意:在 OnCreate() 中)

       ...


 final View blankCard = findViewById(R.id.child_card_template);
    blankCard.setVisibility(blankCard.INVISIBLE);

       ...

    ImageButton btn = (ImageButton) findViewById(R.id.imageLeft);
    btn.setOnClickListener(new View.OnClickListener() {

        int click_Animation_Type = 0;

        View viewTest = findViewById(R.id.child_card_template);
        View viewCard = viewTest;

        @Override
        public void onClick(View view) {
            switch(click_Animation_Type) {
                case 0:
                    moveSecondRow();
                    moveCardViewLayout();
                    click_Animation_Type = 1;
                    break;

                case 1:
                    rewindSecondRow();
                    rewindCardViewLayout();
                    click_Animation_Type = 0;
                    break;
            }
        }

            public void moveCardViewLayout() {
                View viewTest = findViewById(R.id.child_card_template);
                ObjectAnimator viewTestMovi = ObjectAnimator.ofFloat(viewTest, "translationY", 0f, 258f);
                if(viewTest.getVisibility()==View.INVISIBLE) {
                    viewTestMovi.setDuration(250);
                    viewTestMovi.start();
                    viewTest.setVisibility(viewTest.VISIBLE);
                }
            }

            public void rewindCardViewLayout() {
                View viewTest = findViewById(R.id.child_card_template);
                ObjectAnimator viewTestMoviReverse = ObjectAnimator.ofFloat(viewTest, "translationY", 258f, 0f);
                if (viewTest.getVisibility() == View.VISIBLE) {
                    viewTestMoviReverse.setDuration(250);
                    viewTestMoviReverse.start();
                    viewTest.setVisibility(viewCard.INVISIBLE);

                    //THERE'S NO ANIMATION, JUST TURNING INVISIBLE.
                    //Registers View is visible.
                }
            }

            public void moveSecondRow() {
                for (int i = 0; i < list.size(); i++) {
                    ObjectAnimator bottomRow = ObjectAnimator.ofFloat(list.get(i), "translationY", 0f, 300f);
                    bottomRow.setDuration(250);//set duration
                    Animation fadeOutAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out_anim);
                    bottomRow.start();//start animation
                    list.get(i).startAnimation(fadeOutAnimation);
                    list.get(i).setVisibility(View.GONE);
                }
            }

            public void rewindSecondRow() {
                for (int i = 0; i < list.size(); i++) {
                    ObjectAnimator bottomRow = ObjectAnimator.ofFloat(list.get(i), "translationY", 300f, 0f);
                    bottomRow.setDuration(300);//set duration
                    Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in_anim);
                    bottomRow.start();//start animation
                    list.get(i).setVisibility(View.VISIBLE);
                    list.get(i).startAnimation(fadeInAnimation);
                }
            }

    });

每次click_Animation_Type都从0开始。将click_Animation_Type = 0;层放在setContentView下面。