使用bringToFront()方法时遇到麻烦

时间:2013-01-09 13:31:32

标签: android android-layout android-animation

嗨朋友我刚接触到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);

 }
 }

这里iam在点击特定按钮时使用两个标记为body和enevelope我在这里调用了bringToFront()方法,它调用正确并且标志值正在改变但是我不知道在到达前它自动进入后台一些情况 请帮帮我

由于

1 个答案:

答案 0 :(得分:1)

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