Difference Between View.invisible And Value Of Android:invisible
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
Solution 1:
Both are difference. According to Android Reference
textView.setVisibility(1);
is same with
textView.setVisibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
If you want to hide the view, use :
textView.setVisibility(View.INVISIBLE);
Or
textView.setVisibility(4);
Solution 2:
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:
finalint 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:
privatestaticfinalint[] 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}.
*/publicstaticfinalint 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}.
*/publicstaticfinalint 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}.
*/publicstaticfinalint GONE = 0x00000008;
So even if you use the android:invisible in the manifest file, Android framework will finally call setVisibility(...) with the value 4.
Post a Comment for "Difference Between View.invisible And Value Of Android:invisible"