嗨,朋友们,我是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每当单击特定按钮时都会使用两个标志分别用于身体和信封iam调用BringToFront()方法在这里它调用正确并且标志值正确更改,但是在某些情况下出现在前面之后我不知道它会自动变为背景
请帮我
谢谢
最佳答案
现在解决了这个问题,我做的错误是代码的其他部分,我编写了影响我的动画的语句bodyLayout.setVisisbility(View.GONE),