Android - fragmentTransaction.replace () não funciona na biblioteca de suporte 25.1.0
Substituo um FrameLayout por um fragmento usandofragmentTransaction.replace()
.
Layout:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
Substituindo no onCreate da atividade:
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;
}
Mas oview.setVisibility(View.GONE);
não está funcionando na biblioteca de suporte 25.1.0. Portanto, o fragmento ainda será exibido na tela. Se eu definir a visibilidade doarticlesAppender
paraGONE
. Portanto, deve ficar assim:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</FrameLayout>
Em seguida, o fragmento não ficará visível na tela, mas quando tento ligarview.setVisibility(View.VISIBLE);
depois, ainda não funciona. O fragmento ainda não está visível.
Isso significa que oview
que é retornado porinflater.inflate(R.layout.articles_fragment, container, false);
não é a visão real do fragmento. Mas funciona perfeitamente na biblioteca de suporte 25.0.1.
Então é um bug do Android?