- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在用代号一写一个简单的游戏,我希望用户选择国家。
我希望在可滚动列表中将国家表示为图像。
我有一个在 X 轴上带有 BoxLayout 的容器,以及内部带有图标的按钮。
问题是不适合容器的列表项正在被裁剪并且没有在应该绘制的时候绘制。此外,当手指位于未绘制项目上方时,容器不可滚动。
And here how it looks like after scroll
这是来源:
final Container cont_nations = new Container(new BoxLayout(BoxLayout.X_AXIS));
int buttons_width = dim_nation_man.getWidth() * 5;
cont_nations.setPreferredW(buttons_width + 50);
cont_nations.setPreferredH(dim_nation_man.getHeight());
cont_nations.setX(Main.screenWidthHalf - buttons_width / 2);
cont_nations.setY(choiseImage.getY() + dim_choise.getHeight() + Main.cellSize * 0);
cont_nations.setScrollSize(new Dimension(man_size * imgName_nations.length, man_size));
cont_nations.setScrollable(true);
//cont_nations.setScrollVisible(false);
addComponent(cont_nations);
for (int i = 0; i < img_nations.length; i++) {
final Button btn_nation = new Button(img_nations[i][0].image);
cont_nations.addComponent(btn_nation);
}
我知道我做错了。也许我不应该使用Container,或者我应该以另一种方式用 child 填充它,或者为 child 使用另一个类。但我找不到任何信息出了什么问题。
编辑
我尝试了 Shai Almog 的建议,仅使用 setScrollableX(),但这并没有按照我的需要工作。容器移至左上角并且不可滚动。
首先,我需要此滚动位于特定位置并具有特定大小,因此我使用 CoordinationLayout 作为容器的父级。这就是为什么我将 setX()、setY() 和 setPreferredW() 与 setPreferredH() 一起使用。
最佳答案
您只想在 X 轴上滚动吗?
删除所有这些代码:
int buttons_width = dim_nation_man.getWidth() * 5;
cont_nations.setPreferredW(buttons_width + 50);
cont_nations.setPreferredH(dim_nation_man.getHeight());
cont_nations.setX(Main.screenWidthHalf - buttons_width / 2);
cont_nations.setY(choiseImage.getY() + dim_choise.getHeight() + Main.cellSize * 0);
cont_nations.setScrollSize(new Dimension(man_size * imgName_nations.length, man_size));
cont_nations.setScrollable(true);
按钮将根据其图标大小调整大小,因此您无需触摸它。设置位置将不起作用,因为布局管理器将确定这一点。
只需使用:
cont_nations.setScrollableX(true);
注意最后的X
...
由于您的评论,为了完整起见,我添加了一个完整的工作示例来证明这一点:
Form hi = new Form("Side Scroll");
hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
int[] colors = { 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000 };
Container side = new Container(new BoxLayout(BoxLayout.X_AXIS));
side.setScrollableX(true);
hi.addComponent(side);
for(int iter = 0 ; iter < 30 ; iter++) {
side.addComponent(new Button(Image.createImage(100, 50, colors[iter % colors.length])));
}
hi.show();
关于android - 代号 One BoxLayout 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34056010/
我正在尝试使用 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 设备上却不行。我希望该应用程序能够像模拟器上一
我是一名优秀的程序员,十分优秀!