Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android – fragmentTransaction.replace()不适用于支持库25.1.0大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用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的错误吗?

解决方法

@H_696_32@ 报告问题.更多的人似乎有这个问题

https://code.google.com/p/android/issues/detail?id=230191

大佬总结

以上是大佬教程为你收集整理的Android – fragmentTransaction.replace()不适用于支持库25.1.0全部内容,希望文章能够帮你解决Android – fragmentTransaction.replace()不适用于支持库25.1.0所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。