android 隐藏视图,使用animation隐藏视图并将可见性设置为不闪烁屏幕

在Android应用开发中,遇到一个视图隐藏动画导致屏幕闪烁的问题。通过设置Animation的setFillAfter属性为true可以消除闪烁,但由此导致主板内ScrollView无法滚动。最终通过监听Animation的onAnimationEnd事件并在其中设置视图不可见,成功解决了两者之间的冲突,同时保持了滚动功能。
摘要由CSDN通过智能技术生成

我想隐藏dicelayout(dicelout在mainboardlinear中)但是当animation完成时,由于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();

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

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值