Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 动画对象位于视图后面_Android - Fatal编程技术网

Android 动画对象位于视图后面

Android 动画对象位于视图后面,android,Android,该应用程序基本上是一个蛇和梯子类型的应用程序,我掷骰子,并期望玩家的作品动画(翻译)的结果框。 但这并没有发生,当它离开父框时,它就隐藏在其他框的后面,这就是为什么: 我想不出原因 代码如下: public void move(final int frombox, final int tobox){ /*Condition for first roll, it's direct, haven't coded it's animation yet */ if(box

该应用程序基本上是一个蛇和梯子类型的应用程序,我掷骰子,并期望玩家的作品动画(翻译)的结果框。 但这并没有发生,当它离开父框时,它就隐藏在其他框的后面,这就是为什么: 我想不出原因

代码如下:

public void move(final int frombox, final int tobox){
        /*Condition for first roll, it's direct, haven't coded it's animation yet */
        if(box0.indexOfChild(playerPiece[turnInt])!=-1) {
            box0.removeView(playerPiece[turnInt]);
            boxes[tobox].addView(playerPiece[turnInt]);
        }
        else {
            animate(playerPiece[turnInt], frombox, tobox);
        }
    }

    private void animate(View v,final int frombox, final int tobox) {
        AnimatorSet animSetXY = new AnimatorSet();

        ObjectAnimator y = ObjectAnimator.ofFloat(v,
                "translationY",v.getY(), boxes[tobox].getY());

        ObjectAnimator x = ObjectAnimator.ofFloat(v,
                "translationX", v.getX(), boxes[tobox].getX());

        animSetXY.playTogether(x, y);
        //animSetXY.setInterpolator(new LinearInterpolator());
        animSetXY.setDuration(1000);
        animSetXY.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {}

            @Override
            public void onAnimationEnd(Animator animation) {
                boxes[frombox].removeView(playerPiece[turnInt]);
                Log.i("Check", "Removed from " + frombox);
                boxes[tobox].addView(playerPiece[turnInt]);
                Log.i("Check", "Added to " + tobox);
                playerPiece[turnInt].clearAnimation();
            }

            @Override
            public void onAnimationCancel(Animator animation) {}

            @Override
            public void onAnimationRepeat(Animator animation) {}
        });
        animSetXY.start();
    }

日志消息确实显示了从正确位置添加和删除的视图,但在第一个动画之后(即在第二个滚动之后,因为第一个滚动是直接的)它永远不可见。

要将它带到前面,您应该使用
bringToFront()
方法

v.bringToFront();

要将其放在前面,您应该使用
bringToFront()
方法

v.bringToFront();

(1) 它应该是playerPice[turnInt].bringToFront(),AnimSet没有该方法。(2) 没有帮助,在3个地方尝试过,但视图仍然保留。@Abhijeet是的。这是错误的,它应该被调用到你想要展现的观点上。是的,我发现了,但这不是正确的解决方案。不幸的是,观点仍然存在behind@Abhijeet你明白了吗?发布你自己的答案,其他人会从中吸取教训:)干杯(:不,我的意思是我认为应该在视图中调用它,而不是答案:)(1)应该是playerPice[turnInt]。bringToFront(),AnimSet没有这种方法。(2) 没有帮助,在3个地方尝试过,但视图仍然保留。@Abhijeet是的。这是错误的,它应该被调用到你想要展现的观点上。是的,我发现了,但这不是正确的解决方案。不幸的是,观点仍然存在behind@Abhijeet你明白了吗?发布你自己的答案,其他人会从中吸取教训:)干杯(:不,我的意思是我认为应该在视图中显示出来,而不是答案:)