Android:隐形和消失之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11556607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android : difference between invisible and gone?
提问by Rob
What is the difference between invisible
and gone
for the View visibility status?
View 可见性状态invisible
和gone
View 可见性状态有什么区别?
回答by I?igo
INVISIBLE:
无形的:
This view is invisible, but it still takes up space for layout purposes.
这个视图是不可见的,但它仍然占用布局空间。
GONE:
走了:
This view is invisible, and it doesn't take any space for layout purposes.
这个视图是不可见的,它不占用任何布局空间。
回答by Pankaj Kumar
From Documentationyou can say that
从文档中你可以说
View.GONEThis view is invisible, and it doesn't take any space for layout purposes.
View.INVISIBLEThis view is invisible, but it still takes up space for layout purposes.
View.GONE这个视图是不可见的,它不占用任何布局空间。
View.INVISIBLE这个视图是不可见的,但它仍然占据布局空间。
Lets clear the idea with some pictures.
让我们用一些图片来澄清这个想法。
Assume that you have three buttons, like below
假设您有三个按钮,如下所示
Now if you set visibility of Button Two as invisible (View.INVISIBLE
), then output will be
现在,如果您将按钮二的可见性设置为不可见 ( View.INVISIBLE
),则输出将为
And when you set visibility of Button Two as gone (View.GONE
) then output will be
当您将按钮二的可见性设置为消失 ( View.GONE
) 时,输出将是
Hope this will clear your doubts.
希望这会消除您的疑虑。
回答by mes
For ListView or GridView there is an another difference, when visibility initially set to
对于 ListView 或 GridView 有另一个区别,当可见性最初设置为
INVISIBLE:
无形的:
Adapter's getView() function called
调用了适配器的 getView() 函数
GONE:
走了:
Adapter's getView() function didn't call, thus preventing views to load, when it is unnecessary
适配器的 getView() 函数未调用,因此在不必要时会阻止加载视图
回答by twlkyao
INVISIBLE:
The view has to be drawn and it takes time.
不可见:
必须绘制视图并且需要时间。
GONE:
The view doesn't have to be drawn.
GONE:
不必绘制视图。
回答by Rafael Ruiz Mu?oz
I'd like to add to the right and successful answers, that if you initialize a view with visibility as View.GONE
, the view could have been not initialized and you will get some random errors.
我想补充正确且成功的答案,如果您将视图初始化为可见性View.GONE
,则视图可能尚未初始化,您将收到一些随机错误。
For example if you initialize a layout as View.GONE
and then you try to start an animation, from my experience I've got my animation working randomly times. Sometimes yes, sometimes no.
例如,如果您将布局初始化为View.GONE
,然后尝试启动动画,根据我的经验,我的动画会随机工作几次。有时是,有时不是。
So before handling (resizing, move, whatever) a view, you have to init it as View.VISIBLE
or View.INVISIBLE
to render it (draw it) in the screen, and then handle it.
因此,在处理(调整大小、移动等)视图之前,您必须将其初始化为View.VISIBLE
或View.INVISIBLE
渲染(绘制)在屏幕中,然后处理它。
回答by kuldeep zala
when you make it Gone every time of compilation of program the component gets initialized that means you are removing the component from layout and when you make it invisible the component it will take the same space in the layout but every time you dont need to initialize it.
当你每次编译程序时都让它消失时,组件被初始化,这意味着你正在从布局中删除组件,当你让它不可见时,组件将在布局中占用相同的空间,但每次你都不需要初始化它.
if you set Visibility=Gone then you have to initialize the component..like
如果你设置 Visibility=Gone 那么你必须初始化组件..like
eg Button _mButton = new Button(this);
例如 Button _mButton = new Button(this);
_mButton = (Button)findViewByid(R.id.mButton);
_mButton = (Button)findViewByid(R.id.mButton);
so it will take more time as compared to Visibility = invisible.
因此与 Visibility = invisible 相比,它需要更多时间。
回答by Yugandhar Vadlamudi
View.INVISIBLE->The View is invisible but it will occupy some space in layout
View.GONE->The View is not visible and it will not occupy any space in layout
View.INVISIBLE-> 视图是不可见的,但它会在布局中占据一些空间
View.GONE-> 视图不可见,不会在布局中占据任何空间
回答by MKH
View.GONE = The view will not show and the rest of the views will not take its existence into consideration
View.GONE = 视图不会显示,其余的视图不会考虑它的存在
View.INVISIBLE = The view will not show, but it will take its assigned space in the layout
View.INVISIBLE = 视图不会显示,但会在布局中占用分配的空间