Codename One 转换表单自动滚动到顶部
Codename One Transition Form Automatically Scrolls to Top
我有一个应用程序,其中包含许多使用幻灯片切换的组件。
组件、ScaleImageButtons 和 -Labels 通过 GridLayout 直接添加到表单中。还涉及计时器事件,使场景更加动态和吸引人
表单当然是可滚动的。
现在,每次我调用表单并将其向下滚动时,它会自动跳回到表单顶部的第一个项目,一旦它变成动画。
但是表单应该停留在当前滚动位置,与动画项目的位置无关,是否可见。
如何使窗体保持当前滚动位置,独立于当前动画项目的位置?
formApps.setFocusScrolling(false); // does not help
代码如下:
(编辑此代码以反映工作解决方案)
Form formApps = new Form(new GridLayout(6, 2));
ArrayList<String> listApps = classStrings.listApps;
for (int i = 0; i < listApps.size(); i++) {
Container container = new Container();
ScaleImageButton scaleImageButton = new ScaleImageButton(image);
SpanButton spanButton = new SpanButton(stringDescrip);
container.add(scaleImageButton);
UITimer uit00 = new UITimer(() -> {
UITimer uit01 = new UITimer(() -> {
container.replace(spanButton, scaleImageButton,
CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, true, slideInterval));
});
uit01.schedule(startInterval, false, formApps);
UITimer uit02 = new UITimer(() -> {
container.replace(scaleImageButton, spanButton,
CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, true, slideInterval));
});
uit02.schedule(repeatIntervalOne, false, formApps);
});
uit00.schedule(repeatIntervalOne, true, formApps);
});
form.setFocusScrolling(false);
form.add(container);
container.setScrollableY(true);
formApps.show();
你不应该在这里直接使用 Timer
。那violates the EDT。您应该将计时器回调包装在 callSerially
中,或者更好的是只使用专为这个目的而设计的 UITimer
。
6x2 是一个相对较小的网格,因此当元素调整大小时,一个小的移动就足以将您带到顶部。网格的大小由其中所有元素的首选大小决定。如果 scaleImageButton
比 spanButton
大得多,一旦它们被替换,布局可能 "jump" 并且你最终会得到更小的东西,感觉像滚动但只是一个新的布局,因为更小首选尺码。
解决此问题的方法是:
Component.setSameSize(scaleImageButton, spanButton);
我有一个应用程序,其中包含许多使用幻灯片切换的组件。
组件、ScaleImageButtons 和 -Labels 通过 GridLayout 直接添加到表单中。还涉及计时器事件,使场景更加动态和吸引人
表单当然是可滚动的。
现在,每次我调用表单并将其向下滚动时,它会自动跳回到表单顶部的第一个项目,一旦它变成动画。
但是表单应该停留在当前滚动位置,与动画项目的位置无关,是否可见。
如何使窗体保持当前滚动位置,独立于当前动画项目的位置?
formApps.setFocusScrolling(false); // does not help
代码如下:
(编辑此代码以反映工作解决方案)
Form formApps = new Form(new GridLayout(6, 2));
ArrayList<String> listApps = classStrings.listApps;
for (int i = 0; i < listApps.size(); i++) {
Container container = new Container();
ScaleImageButton scaleImageButton = new ScaleImageButton(image);
SpanButton spanButton = new SpanButton(stringDescrip);
container.add(scaleImageButton);
UITimer uit00 = new UITimer(() -> {
UITimer uit01 = new UITimer(() -> {
container.replace(spanButton, scaleImageButton,
CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, true, slideInterval));
});
uit01.schedule(startInterval, false, formApps);
UITimer uit02 = new UITimer(() -> {
container.replace(scaleImageButton, spanButton,
CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, true, slideInterval));
});
uit02.schedule(repeatIntervalOne, false, formApps);
});
uit00.schedule(repeatIntervalOne, true, formApps);
});
form.setFocusScrolling(false);
form.add(container);
container.setScrollableY(true);
formApps.show();
你不应该在这里直接使用 Timer
。那violates the EDT。您应该将计时器回调包装在 callSerially
中,或者更好的是只使用专为这个目的而设计的 UITimer
。
6x2 是一个相对较小的网格,因此当元素调整大小时,一个小的移动就足以将您带到顶部。网格的大小由其中所有元素的首选大小决定。如果 scaleImageButton
比 spanButton
大得多,一旦它们被替换,布局可能 "jump" 并且你最终会得到更小的东西,感觉像滚动但只是一个新的布局,因为更小首选尺码。
解决此问题的方法是:
Component.setSameSize(scaleImageButton, spanButton);