滚动选项卡时工具栏淡入淡出(代号一)

2023-12-21

Codename One 手册中的“如何在滚动时淡出工具栏”部分描述了如何在滚动时淡出工具栏标题动画": https://www.codenameone.com/manual/components.html#title-animations-section https://www.codenameone.com/manual/components.html#title-animations-section

示例代码(取自给定链接)有效。我稍微修改了它,因为我需要在滚动选项卡时淡入工具栏,但我的代码不起作用。你能帮我修复它吗?请尝试滚动“Tab 3”(这是唯一可滚动的),我在 Codename One Simulator 中使用 iPhone 皮肤进行了测试。谢谢

    Form hi = new Form("Toolbar", new BorderLayout());
    EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
    URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
            "http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg");
    background.fetch();
    Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
    stitle.setBgImage(background);
    stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
    stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
    stitle.setPaddingTop(15);
    SpanButton credit = new SpanButton("This excerpt is from A Wiki Of Ice And Fire. Please check it out by clicking here!");
    credit.addActionListener((e) -> Display.getInstance().execute("http://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));

    Tabs tabs = new Tabs();
    Container cnt3 = BoxLayout.encloseY(new SpanLabel("A Game of Thrones is set in the Seven Kingdoms of Westeros, a land reminiscent of Medieval Europe. In Westeros the seasons last for years, sometimes decades, at a time.\n\nFifteen years prior to the novel, the Seven Kingdoms were torn apart by a civil war, known alternately as \"Robert's Rebellion\" and the \"War of the Usurper.\" Prince Rhaegar Targaryen kidnapped Lyanna Stark, arousing the ire of her family and of her betrothed, Lord Robert Baratheon (the war's titular rebel). The Mad King, Aerys II Targaryen, had Lyanna's father and eldest brother executed when they demanded her safe return. Her second brother, Eddard, joined his boyhood friend Robert Baratheon and Jon Arryn, with whom they had been fostered as children, in declaring war against the ruling Targaryen dynasty, securing the allegiances of House Tully and House Arryn through a network of dynastic marriages (Lord Eddard to Catelyn Tully and Lord Arryn to Lysa Tully). The powerful House Tyrell continued to support the King, but House Lannister and House Martell both stalled due to insults against their houses by the Targaryens. The civil war climaxed with the Battle of the Trident, when Prince Rhaegar was killed in battle by Robert Baratheon. The Lannisters finally agreed to support King Aerys, but then brutally... "));
    cnt3.setScrollableY(true);
    tabs.addTab("Tab 1", new SpanLabel("A Game of Thrones is the first of seven planned novels in A Song of Ice and Fire, an epic fantasy series by American author George R. R. Martin. It was first published on 6 August 1996. The novel was nominated for the 1998 Nebula Award and the 1997 World Fantasy Award,[1] and won the 1997 Locus Award.[2] The novella Blood of the Dragon, comprising the Daenerys Targaryen chapters from the novel, won the 1997 Hugo Award for Best Novella. "));
    tabs.addTab("Tab 2", new Label("Plot introduction", "Heading"));
    tabs.addTab("Tab 3", cnt3);

    hi.add(BorderLayout.CENTER, tabs);

    ComponentAnimation title = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
    hi.getAnimationManager().onTitleScrollAnimation(title);
    hi.show();

在更好地阅读了 Javadocs 后,我发现了这个可能的解决方案:

ComponentAnimation title = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
        for (int i = 0; i < tabs.getTabCount(); i++) {
            Component tab = tabs.getTabComponentAt(i);
            if (tab instanceof Container) {
                hi.getAnimationManager().onTitleScrollAnimation((Container)tab, title);
            }
        }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

滚动选项卡时工具栏淡入淡出(代号一) 的相关文章

  • 为什么 Chrome 在响应模式下缩小视图?

    我有一个应该具有响应能力的页面 它还有一个适用于移动设备的视口标签 如下所示 然而 在 Chrome 开发工具中 当页面首先以横向模式查看然后旋转到纵向模式时 即使 html 页面的宽度是旋转后设备的宽度 即 400px 页面尺寸也会变得非

随机推荐