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;
Here is the content of VISIBILITY_FLAGS:
private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};
The value of the array elements are actually the value shown in Android Reference
/**
* 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;
So even if you use the android:invisible in the manifest file, Android framework will finally call setVisibility(...) with the value 4.
View.INVISIBLEis4.