I replace a FrameLayout with a fragment using fragmentTransaction.replace()
.
Layout:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
Replacing in Activity's 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's 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 the view.setVisibility(View.GONE);
is not working on support library 25.1.0.
So the fragment will still be displayed on the screen.
If I set the visibility of the articlesAppender
to GONE
.
So 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 the fragment will not be visible on the screen, but when I try to call view.setVisibility(View.VISIBLE);
later, it still not works.
The fragment still not be visible.
That means the view
which is returned by inflater.inflate(R.layout.articles_fragment, container, false);
is not the real view of the fragment.
But it works perfectly on support library 25.0.1.
So it's an Android's bug?