使用动画隐藏视图并将可见性设置为不闪烁屏幕

时间:2013-07-04 08:48:53

标签: android animation

我想隐藏dicelayout(dicelout在主板上),但是当动画完成时,由于View.GONE,屏幕闪烁! 如果我将setfillafter设置为true并清除View.GONE,我不再有flash问题了,但在这种情况下我的主板内的scrollview无法滚动!

                final RelativeLayout rLayout=(RelativeLayout)findViewById(R.id.dicelayout);


            Animation animation=new TranslateAnimation(0, 0, 0, -rLayout.getHeight());
            animation.setFillAfter(false);
            animation.setFillBefore(true);
            animation.setDuration(1000);
            ((LinearLayout)findViewById(R.id.mainboardlinear)).startAnimation(animation);


            Thread t=new Thread(new Runnable() {
                public void run() {
                try {
                    Thread.sleep(999);
                    runOnUiThread(new Runnable() {
                        public void run() {

                        rLayout.setVisibility(View.GONE);
                        }
                    });

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
                }
            });
            t.start();

1 个答案:

答案 0 :(得分:11)

使用setAnimationListener和setFillEnabled中的onAnimationEnd解决了我的问题。

Animation animation=new TranslateAnimation(0, 0, 0, -rLayout.getHeight());
            animation.setFillEnabled(true);

            animation.setDuration(1000);
            animation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationEnd(Animation animatiofillAftern) {
                    // TODO Auto-generated method stub
                    //                      mainBoardLinear.removeView(rLayout);
                    rLayout.setVisibility(View.GONE);

                }
            });

            mainBoardLinear.startAnimation(animation);