- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习有关如何在使用代号一创建的移动应用程序中开始制作动画的基本教程。
https://www.codenameone.com/manual/animations.html
虽然我得到了在容器上使用布局动画和取消布局动画来将事物移入和移出位置的概念,但这似乎不适用于取消布局动画。
下面代码的想法是根据某些搜索结果显示或隐藏元素列表(该示例只有普通标签)。单独使用时,就地动画效果很好,如教程中所示。
但是为什么在调用“animateUnlayoutAndWait()”时一切都完全消失了?
Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button button = new Button("Hide");
hi.add(button);
for (int iter = 0; iter < 10; iter++) {
Label b = new Label("Label " + iter);
b.setWidth(button.getWidth());
b.setHeight(button.getHeight());
b.setY(-button.getHeight());
hi.add(b);
}
button.addActionListener((e) -> {
// hide every second label on click
if (button.getText().equals("Hide")) {
button.setText("Show");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(false);
}
hi.getContentPane().animateUnlayoutAndWait(500, 0);
}
// show stuff again
else {
button.setText("Hide");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(true);
}
hi.getContentPane().animateLayoutAndWait(500);
}
});
hi.show();
谢谢和最好的问候
最佳答案
我注意到您错误地交换了 setHidden()
值,if
部分应该为真而 else
部分应该为假。此外,从动画中删除 AndWait
。
Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button button = new Button("Hide");
hi.add(button);
for (int iter = 0; iter < 10; iter++) {
Label b = new Label("Label " + iter);
b.setWidth(button.getWidth());
b.setHeight(button.getHeight());
b.setY(-button.getHeight());
hi.add(b);
}
button.addActionListener((e) -> {
// hide every second label on click
if (button.getText().equals("Hide")) {
button.setText("Show");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(true); //should be true here
}
hi.getContentPane().animateUnlayout(500, 255, null); //remove AndWait
} // show stuff again
else {
button.setText("Hide");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(false); //should be false here
}
hi.getContentPane().animateLayout(500); //remove AndWait
}
});
hi.show();
关于java - 代号一 - 隐藏单个元素的动画删除所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42377003/
我正在尝试使用 Eclipse 和 codename one 跨平台环境建立与数据库的在线连接。 很明显,将本地数据库放在默认文件夹中可以让您访问数据库,连接代码如下: db = Display.ge
我正在尝试通过代码在我的应用程序上打开侧面菜单。 我的表单使用工具栏用更复杂的组件填充侧面菜单。 我用它来关闭菜单: SideMenuBar.closeCurrentMenu(); 但我找不到等效的打
我正在使用 Codename One 开发移动应用。 我有一个外部容器,我通过调用方法 addPointerReleasedListener 添加了一个 ActionListener。 还有更多未添加
现在我正在使用 Codename one Calendar API,它工作正常,但我在日历 ui 方面遇到了一些设计问题。我的要求是当我点击特定的一天并将其添加为事件日时,那么该日的颜色就会改变。 以
我正在 Samsung Galaxy Tab A 10.1 (2019) 上测试我的应用(调试版本)。设备分辨率为 1200 x 1920。但是,当我使用 getDisplayWidth() 和 ge
我正在用 Textfield 创建一个 GenericListCellRenderer,我需要编辑 textfield 并替换其中的值,但我没有单击 Textfield 时获得任何焦点。我试过的代码如
Codename One动画发生了什么?我使用了很多,自12月起,我的应用程序不再起作用。当我在六月离开东西时,一切都很好(至今已经一年多了)。 我的应用程序是草稿(跳棋)游戏,自2013年以来在应用
我正在尝试为 Android 发布我的 Codename One-built 应用程序,但在尝试上传新版本(发布 apk 或 aab)时,我卡在了 Google Play 控制台上。 自 2021 年
我正在尝试在 Codename One 中使用计时器,但它只有“UITimer”,我似乎无法弄清楚也找不到任何示例。 所以我尝试了 Swing 计时器,但它给了我错误: codename1.ui.ev
我的应用程序构建正常,但是当我添加库 parse4cn1 时,构建失败 ios 失败示例: CompileC build/Main.build/Release-iphoneos/Main.build/
在代号一中,我试图实现一张用户卡,其中包含一些描述和两个操作按钮(调用和短信),位于卡的底部,彼此水平放置。有没有办法“分割”最后一个文本行?帮助会很棒! 谢谢! 最佳答案 您可以将这 2 个按钮放置
我目前正在用代号一写一个简单的游戏,我希望用户选择国家。 我希望在可滚动列表中将国家表示为图像。 我有一个在 X 轴上带有 BoxLayout 的容器,以及内部带有图标的按钮。 问题是不适合容器的列表
我正在尝试使用 setBrowserNavigationCallback BrowserComponent 的方法从 html 页面调用 java 方法。 这就是我在java中的内容:
我尝试将我的 Codename One 应用程序发送到构建服务器来构建 Android 应用程序,但它一直失败。一切在模拟器上运行良好,没有错误。唯一的问题是当我尝试将项目发送到构建服务器时。这是错误
我正在尝试以代号一创建一个音乐播放应用程序,在向媒体播放器添加 slider 时遇到问题。应用程序运行时会显示 slider ,但播放文件时不会显示进度。这是我用来添加自定义播放和暂停按钮以及 sli
我习惯用 Java 开发桌面应用程序。现在我正在尝试使用 Codename One 开发我的第一个移动应用程序。 在尝试复制我在 SQL 数据库方面的经验时,我遇到了一种非常奇怪的存储行为,我无法解释
我正在尝试使用我的 cn1 android 应用程序获取推送通知。我让它在 ios 上完美运行,但出于某种原因,它甚至没有在 android 上注册。这是我做的 我在我的 Play 商店控制台中启动了
我在 iPhone 7 上运行了一个代号为 one 的程序。那部手机最近没电了,我得到了 iPhone11 pro。我从旧手机中删除了 UDID,并将新手机的 UDID 添加到我的苹果开发者帐户中。我
我有一个图标按钮,带有一个小方形图标。 按钮嵌入在 BoxLayout 中。 有没有办法减小按钮的大小,以便自动达到图标的准确大小? 我的意思是,我知道我可以更改按钮的大小编辑边距和填充,但我想问我是
我正在创建一个媒体播放器应用程序,该应用程序应该从远程 URL 流式传输 mp3 文件。问题是,在代号为一个模拟器上一切正常,但在实际的 Android 设备上却不行。我希望该应用程序能够像模拟器上一
我是一名优秀的程序员,十分优秀!