Fragment android:visibility in xml layout definition -
how works? have layout below:
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:id="@+id/search_form_fragment" android:name="fragmentclass" android:layout_width="match_parent" android:layout_height="match_parent" /> <fragment android:id="@+id/result_list_fragment" android:name="fragmentclass" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" /> </linearlayout>
note second fragment has android:visibility="gone"
, indeed not visible on screen. code:
boolean bothvisible = firstfrag.isvisible() && secondfrag.isvisible();
returns true
, not expected me. wonder if using android:visibility
correct cause not find information in documentation.
per fragment source, isvisible
defined as:
final public boolean isvisible() { return isadded() && !ishidden() && mview != null && mview.getwindowtoken() != null && mview.getvisibility() == view.visible; }
i.e., attached activity, not hidden (via fragmenttransaction.hide), view inflated, view attached window, , interior view of fragment view.visible
.
i believe issue in order inflate fragment, system creates layout hold fragment's view. view setting view.gone
, not interior view fragment creates.
i might suggest changing condition be:
findviewbyid(r.id.result_list_fragment).getvisibility() == view.visible
Comments
Post a Comment