我使用片段替换 FrameLayoutfragmentTransaction.replace()
.
Layout:
<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;
}
But the view.setVisibility(View.GONE);
不适用于支持库 25.1.0。
所以该片段仍然会显示在屏幕上。
如果我设置的可见性articlesAppender
to GONE
。
所以它应该看起来像这样:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</FrameLayout>
然后片段将在屏幕上不可见,但是当我尝试调用时view.setVisibility(View.VISIBLE);
后来还是不行。
该片段仍然不可见。
这意味着view
由返回inflater.inflate(R.layout.articles_fragment, container, false);
不是片段的真实视图。
但它在支持库 25.0.1 上完美运行。
那么这是 Android 的 bug 吗?