当前位置: 首页 > 知识库问答 >
问题:

android中碎片的交易结果为空白屏幕

薛浩言
2023-03-14

如果有帮助的话,我想要的与本谷歌教程中所做的类似

DiceTable diceTable = new DiceTable();
Logger logger = new Logger();
fragmentTransaction.add(diceTable, DICETABLE_TAG);
fragmentTransaction.add(logger, LOGGER_TAG);
fragmentTransaction.add(R.id.fragment_container, logger);
fragmentTransaction.add(R.id.fragment_container, diceTable);
    Logger logger = (Logger)fragmentManager.findFragmentByTag(LOGGER_TAG);
    DiceTable diceTable = (DiceTable)fragmentManager.findFragmentByTag(DICETABLE_TAG);

    if (diceTable.isVisible()) {
        fragmentTransaction.replace(R.id.fragment_container, logger);

        fragmentTransaction.commit();
        fragmentTransaction.hide(diceTable);
        fragmentTransaction.show(logger);
    }
    else if (logger.isVisible()) {
        fragmentTransaction.replace(R.id.fragment_container, diceTable);

        fragmentTransaction.commit();
        fragmentTransaction.hide(logger);
        fragmentTransaction.show(diceTable);
    }

我不应该这样做吗?

替换碎片时的空白屏幕

共有1个答案

汪永春
2023-03-14

尝试用那种方式初始化片段:

private void initFragments() {
    mDiceTable = new DiceTable();
    mLogger = new Logger();
    isDiceTableVisible = true;

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.fragment_container, mDiceTable);
    ft.add(R.id.fragment_container, mLogger);
    ft.hide(mLogger);
    ft.commit();
}

然后以那种方式在它们之间翻转:

 private void flipFragments() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        if (isDiceTableVisible) {
            ft.hide(mDiceTable);
            ft.show(mLogger);
        } else {
            ft.hide(mLogger);
            ft.show(mDiceTable);
        }
        ft.commit();
        isDiceTableVisible = !isDiceTableVisible;
    }
 类似资料:
  • 我有两个碎片。片段A最初在视野中。当用户按下一个按钮时,片段B会使用下面的方法被动画化到视图中。当我弹出片段B时,它会从视野中返回,但当它完成时,屏幕闪烁着白色。不确定是什么原因造成的,似乎只发生在吉吉身上而不是Lollipop上。正在使用的动画是XML中定义的上滑和下滑动画。

  • WebView可以很好地处理http请求和https(其中知名的可信站点如https://www.online.citibank.co.in/),但我试图使用第三方颁发的CA访问私有站点,它显示的是空白屏幕。证书通过SD卡安装到电话上,并列在受信任的证书列表下。 当我在将证书添加到TrustManager后使用HttpsURLConnection尝试相同的URL时,它工作得很好(能够获取内容)。

  • 我最近使用sdks管理器安装了Android Studio及其所有更新。当我尝试启动模拟器时,我可以看到: 模拟器-netdelay none-netspeed full-AVD NEXUS_5_API21_x86 HAX正在工作,仿真程序在快速virt模式下运行 看起来不错。模拟器启动了,但我只能看到一个黑屏。我使用应用程序创建的默认AVD。它拥有谷歌API的x86系统映像、1GB ram、64

  • 我一直在尝试让谷歌地图在Android Studio工作。 使用Google maps模板创建新项目时,效果很好。然而,当我在现有项目中实现地图时,它显示的只是一个灰色屏幕,左下角有一个徽标。 现有项目使用一个片段导航系统和一个单独的活动来承载所有其他片段类。但这不应该是问题的原因,因为我以与模板中相同的方式实现了映射,但它也不起作用。 我检查了Logcat输出,密钥验证没有错误。如果我更改密钥,

  • 我可以使用一个片段作为一个活动吗?我已经创建了一个片段,但我希望它有像活动一样的功能,所以我使用片段扩展碎片活动。然而,我有一个带有碎片的导航抽屉。当我更改为“扩展碎片活动”时,我的代码有问题?请给我指路。

  • 我使用的是EclipseIDE,下面的代码在浏览器上显示空白屏幕。我不知道为什么它会显示空白屏幕。有什么想法吗?提前谢谢。 请查找部署描述符文件。网状物xml: