问题描述
我对Android开发新的,所以我在OnClick事件为我设置按钮的方法开发一个简单的应用程序,它隐藏的TextView pressing一些按钮,这样在java code TextView的为不可见,我用:
I'm new on Android development, so I'm developing an simple application that hides a textview pressing some button, so in the java code in the method for the OnClick event for the button I set the textview as invisible, I used:
textView.setVisibility(1);
由于1是隐形的值Android的参考,但它不工作,所以我用后
because 1 is the value for "invisible" described in the android reference, but it does not work, so after I used
textView.setVisibility(View.INVISIBLE);
和它的作品,所以当使用1的价值呢?而为什么View.INVISIBLE = 4,而不是1作为参考Android的说?
and it works, so When is the "1" value used? and Why is View.INVISIBLE = 4 instead of 1 as the android reference says?
在Android的参考我可以看到隐形的属性的android值:可见性定义为1
In the android reference I can see that the value Invisible for attribute android:visibility is defined as 1
推荐答案
这是一个很好的问题,我查了Android源$ C $ C(框架/基/核心/ JAVA /安卓/查看/ View.java)
This is a good question, I checked the Android source code (frameworks/base/core/java/android/view/View.java)
case com.android.internal.R.styleable.View_visibility:
final int visibility = a.getInt(attr, 0);
if (visibility != 0) {
viewFlagValues |= VISIBILITY_FLAGS[visibility]; //here is the key to your question
viewFlagMasks |= VISIBILITY_MASK;
}
break;
下面是VISIBILITY_FLAGS的内容:
Here is the content of VISIBILITY_FLAGS:
private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};
数组元素的值实际上是
/**
* This view is visible.
* Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
* android:visibility}.
*/
public static final int VISIBLE = 0x00000000;
/**
* This view is invisible, but it still takes up space for layout purposes.
* Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
* android:visibility}.
*/
public static final int INVISIBLE = 0x00000004;
/**
* This view is invisible, and it doesn't take any space for layout
* purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
* android:visibility}.
*/
public static final int GONE = 0x00000008;
因此,即使您使用android:在清单文件中不可见的,Android的框架将最后调用setVisibility(...)值为4。
So even if you use the android:invisible in the manifest file, Android framework will finally call setVisibility(...) with the value 4.
这篇关于View.INVISIBLE和Android的价值之间的差额:隐形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!