I have a problem when views with the GONE visibility state (undesirable) take up space on the screen. This problem always occurs at the API level <= 7, but only recently on 8+ devices (after I used AsyncTasks to fill in some fields, according to the Show progress bar when the action loads )
A little context: I created a custom view that extends LinearLayout, which contains a "title" button and (the user defined, in some cases, several TextViews, in others TableLayouts) "content". The purpose of this view is to switch the content view to the βClickβ button of the header button (I donβt believe that there is a built-in widget for this. Maybe I'm wrong).
In onLayout (), I explicitly set the visibility state of all child views except the GONE header when it is first accessed:
protected void onLayout(boolean changed, int l, int t, int r, int b) { if(initialDraw) { setContentsVisible(false); initialDraw = false; } super.onLayout(changed, l, t, r, b); } public void setContentsVisible(boolean visible) { for(int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); if(child != mTitle) { child.setVisibility(visible ? VISIBLE : GONE); } } }
android android-layout android-widget
Adam
source share