2

嗨朋友们,我是 android 新手,在我的项目中,我有一个要求,我需要在同一位置显示两个布局,并且每当按下按钮时都需要应用旋转动画,我通过在同一位置创建两个布局来实现相同的位置和使用 Layout.bringToFront() 方法在它们之间切换,但我不知道为什么在某些情况下它的动画效果正确,但 BringToFront() 方法没有将我的布局带到前面

 public void bodyClicked()
 {
     System.out.println("Inside Body Clicked...");
     System.out.println("Enevelope boolean value... "+enevelopefocus);
     System.out.println("Body Boolean Value..."+bodyfocus);
     if(!bodyfocus)
        {
            bodyLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_right));
            fromToRootLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this,R.anim.rotate_left));
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            fromToRootLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_center_after_left));
                            bodyLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_right_center));
                            bodyLayout.bringToFront();
                            bodyLayout.invalidate();
                            bodyLayout.requestFocus();
                            bodyfocus=true;
                            enevelopefocus=false;
                            System.out.println("Body CLicked Completed...");
                            System.out.println("Enevelope boolean value... "+enevelopefocus);
                            System.out.println("Body Boolean Value..."+bodyfocus);
                            fromToRootLayout.invalidate();
                        }
                    });

                }
            }, 500);
            headerLayout.setVisibility(View.VISIBLE);


        }
 }
 public void enevlopeCLicked()
 {
     System.out.println("Inside Enevelope Clicked...");
     System.out.println("Enevelope boolean value... "+enevelopefocus);
     System.out.println("Body Boolean Value..."+bodyfocus);
     headerLayout1.setVisibility(View.GONE);
        fromBodyLayout.setVisibility(View.GONE);
        if(fromAddressTExtView.getText().toString().length()>0)
        {
            fromAddressTExtView.setVisibility(View.VISIBLE);
            fromTopEditBtn.setVisibility(View.GONE);
            fromcontactpick.setVisibility(View.GONE);
        }
        else
        {
            fromTopEditBtn.setVisibility(View.VISIBLE);
            fromcontactpick.setVisibility(View.VISIBLE);
            fromAddressTExtView.setVisibility(View.GONE);
        }
        if(toAddressTExtView.getText().toString().length()>0)
        {
            toAddressTExtView.setVisibility(View.VISIBLE);
            toBottomEditBtn.setVisibility(View.GONE);
            toContactPick.setVisibility(View.GONE);
        }
        else
        {
            toBottomEditBtn.setVisibility(View.VISIBLE);
            toContactPick.setVisibility(View.VISIBLE);
            toAddressTExtView.setVisibility(View.GONE);
        }

        if(!enevelopefocus)
        {
            fromToRootLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_left));
            bodyLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this,R.anim.rotate_right));
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            bodyLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_right_center));
                            fromToRootLayout.startAnimation(AnimationUtils.loadAnimation(AddJobNew.this, R.anim.rotate_center_after_left));
                            fromToRootLayout.bringToFront();
                            fromToRootLayout.invalidate();
                            fromToRootLayout.requestFocus();
                            enevelopefocus=true;
                            bodyfocus=false;
                            System.out.println("Enevelope CLicked Completed...");
                            System.out.println("Enevelope boolean value... "+enevelopefocus);
                            System.out.println("Body Boolean Value..."+bodyfocus);
                            bodyLayout.invalidate();
                        }
                    });

                }
            }, 500);
            headerLayout.setVisibility(View.VISIBLE);

 }
 }

在这里,每当单击该特定按钮时,我都会为 body 和信封使用两个标志 iam 在这里调用 bringToFront() 方法,它正在正确调用并且标志值正在正确更改,但我不知道在某些情况下它会自动进入后台帮我

谢谢

4

1 回答 1

1

现在解决了这个问题,我犯的错误是我写了影响我动画的语句 bodyLayout.setVisisbility(View.GONE) 的代码的其他部分,

于 2013-01-11T04:22:15.653 回答