我使用fragmentTransaction.replace()用片段替换FrameLayout.
布局:
<FrameLayout android:id="@+id/articlesAppender" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout>
替换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; }
但是view.setVisibility(View.GONE);不支持库25.1.0.
因此片段仍将显示在屏幕上.
如果我将articlesAppender的可见性设置为GONE.
所以看起来应该是这样的:
<FrameLayout android:id="@+id/articlesAppender" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> </FrameLayout>
然后片段在屏幕上不可见,但是当我尝试调用view.setVisibility(View.VISIBLE)时;后来,它仍然不起作用.
片段仍然不可见.
这意味着inflater.inflate返回的视图(R.layout.articles_fragment,false);不是片段的真实视图.
但它在支持库25.0.1上完美运行.
那是Android的错误吗?
解决方法
报告问题.更多的人似乎有这个问题