我如何检查一个视图可见或不可见的安卓

我如何检查一个视图可见或不可见的安卓

本文介绍了我如何检查一个视图可见或不可见的安卓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置能见度来无形像这样在Android上:

I set visibility to invisible like this on Android:

myImageView.setVisibility(View.INVISIBLE);

然后再使其可见:

And then to make it visible:

myImageView.setVisibility(View.VISIBLE);

现在我不知道,如果 myImageView 可见或不可见,我该怎么检查它是这样的:

Now I don't know if myImageView is visible or not, how can I check it like this:

if (myImageView IS VISIBLE) {
    Do something
} else {
    Do something else
}

我怎么能这样做?我有什么的括号内写?

How can I do that? What do I have to write within the brackets?

推荐答案

虽然View.getVisibility()确实获得知名度,它不是一个简单的真/假。视图可以有它的可见性设置为三件事情之一。

Although View.getVisibility() does get the visibility, its not a simple true/false. A view can have its visibility set to one of three things.

View.VISIBLE 视图是可见的。

View.INVISIBLE 视图是无形的,但任何间隔它通常会占用仍会被使用。它的隐形

View.INVISIBLEThe view is invisible, but any spacing it would normally take up will still be used. Its "invisible"

View.GONE 视图走了,你看不到它,它不占用斑。

View.GONEThe view is gone, you can't see it and it doesn't take up the "spot".

因此​​,要回答你的问题,你要寻找的:

So to answer your question, you're looking for:

if (myImageView.getVisibility() == View.VISIBLE) {
    // Its visible
} else {
    // Either gone or invisible
}

这篇关于我如何检查一个视图可见或不可见的安卓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:02