Kim*_*hiu 6 android fragment android-support-library
我使用片段替换FrameLayout fragmentTransaction.replace().
布局:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
替换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();
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
但是view.setVisibility(View.GONE);不支持库25.1.0.因此片段仍将显示在屏幕上.如果我设置了articlesAppenderto 的可见性GONE.所以看起来应该是这样的:
<FrameLayout
android:id="@+id/articlesAppender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
然后片段在屏幕上将不可见,但是当我稍后尝试呼叫时view.setVisibility(View.VISIBLE);,它仍然不起作用.片段仍然不可见.
这意味着view返回的inflater.inflate(R.layout.articles_fragment, container, false);不是片段的真实视图.但它在支持库25.0.1上完美运行.
那是Android的错误吗?
报告问题.更多的人似乎有这个问题
https://code.google.com/p/android/issues/detail?id=230191
| 归档时间: |
|
| 查看次数: |
1330 次 |
| 最近记录: |