I am replacing FrameLayout with a fragmentTransaction.replace()
using fragmentTransaction.replace()
.
Markup:
<FrameLayout android:id="@+id/articlesAppender" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout>
Replacement in Activity onCreate:
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); articlesFragment = (ArticlesFragment) fragmentManager.findFragmentByTag(ARTICLES_FRAGMENT_TAG); if (articlesFragment == null) { articlesFragment = new ArticlesFragment(); } fragmentTransaction.replace(R.id.articlesAppender, articlesFragment, ARTICLES_FRAGMENT_TAG); fragmentTransaction.commit();
ArticleFragment onCreate:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.articles_fragment, container, false); view.setVisibility(View.GONE); return view; }
But view.setVisibility(View.GONE);
does not work in the support library 25.1.0. Thus, the fragment will be displayed on the screen. If I set the visibility from articlesAppender
to GONE
. Therefore, it should look like this:
<FrameLayout android:id="@+id/articlesAppender" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> </FrameLayout>
Then the fragment will not be visible on the screen, but when I try to call view.setVisibility(View.VISIBLE);
later, it still doesn't work. The fragment is not yet visible.
This means the view
returned by inflater.inflate(R.layout.articles_fragment, container, false);
is not a real kind of fragment. But it works great in the support library 25.0.1.
So, is this an Android bug?