当我调用可见性时,Android动画无效

时间:2018-03-16 05:51:22

标签: android animation visibility

在我将可见性设置为Invisible后,动画无效,我尝试了清晰的动画,但没有工作。当我按下按钮时我有一个按钮它打开一个带有动画的线性布局当我按下后退按钮我将线性布局可见性再次设置为不可见我单击按钮线性布局出现但没有动画请帮助我。

l1 = (LinearLayout) findViewById(R.id.lnrlgn);
  l2 = (LinearLayout) findViewById(R.id.lnrlgn1);
  l2.setVisibility(View.INVISIBLE);
  Animation  uptodown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
  viewcrrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                l2.setAnimation(downtoup);

                l2.clearanimation(); // is it right ?

                l2.setVisibility(View.VISIBLE);

            }
        });
 public void onBackPressed() {
//        super.onBackPressed();

        if (back_pressed + TIME_DELAY > System.currentTimeMillis()) {
//            super.onBackPressed();
            Exitdlg alert = new Exitdlg();
            alert.showDialog(LoginActivity.this, "Are You Sure ");
            l2.clearAnimation();

        } else {

            l2.clearAnimation();


            l2.setVisibility(View.INVISIBLE);



        }
        back_pressed = System.currentTimeMillis();


    }

1 个答案:

答案 0 :(得分:0)

使用startAnimation代替setAnimation

 viewcrrd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            l2.setVisibility(View.VISIBLE);

             l2.clearanimation(); 

            l2.startAnimation(downtoup);

        }
    });