View.isShown()在按下home键之后,返回了false

本文探讨了在Android应用中如何正确判断View的可见性,并提供了解决方案来确保帧动画能在数据更新时准确地停止。文章指出,getVisibility()与isShown()的区别及其在实际场景中的应用。

http://stackoverflow.com/questions/6796299/view-getvisibility-isshown-return-incorrect-visibility


在做某个帧动画的时候,当有数据的时候停止帧动画。

某次按下了home键,回到桌面,数据已经过来,但是View.isShown()返回了false。


getVisibility() simply returns the visibility you want the view to have when added to the window. It doesn't change unless you call setVisibility(). It also doesn't indicate whether the view is actually visible on screen.

isShown() is similar. Here is the doc:

Returns the visibility of this view and all of its ancestors

Returns
True if this view and all of its ancestors are VISIBLE


使用如下方式解决:

if(textView.getVisibility == View.VISIBLE) {
    // do something
}   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值