我在我的应用程序中添加了第二个表单,它在模拟器中从屏幕向左滚动,在屏幕上留下一个空白表单。在所附的代码中,首先显示我从启动屏幕菜单中进行的调用,然后显示我的类。我不知道是什么刷新了我的表单,因为 Shai 确定了我的第一个表单可能发生的情况,而且我不知道我做了什么来阻止第一个表单滚动。有人看到我的错误吗?谢谢。
// Call on Splash Screen
public boolean openField2() throws IOException {
Form mbd = new MoveByDrag();
mbd.show();
return false;
}
// New Form
package com.kcconsulting.soccersession.ui;
import com.codename1.components.ScaleImageLabel;
import com.codename1.ui.*;
import com.codename1.ui.layouts.*;
import com.codename1.io.Log;
import java.io.IOException;
import static com.codename1.ui.CN.getCurrentForm;
import static com.codename1.ui.layouts.BoxLayout.Y_AXIS;
import com.codename1.ui.table.TableLayout;
public class MoveByDrag extends Form {
Form playfield = new Form();
Container controls = new Container();
Container field = new Container();
Image img30;
public MoveByDrag() throws IOException {
TableLayout t2 = new TableLayout(2, 1);
playfield.getToolbar().addMaterialCommandToSideMenu(" Design by Coordinates",
FontImage.MATERIAL_CHECK, 4, e -> {
// Rebuild Menu after stopping Scroll to blank screen
});
playfield.setLayout(t2);
field.getAllStyles().setBgImage(Image.createImage("/BlankField.jpg"));
playfield.add(t2.createConstraint().heightPercentage(10).widthPercentage(100), controls);
playfield.add(t2.createConstraint().heightPercentage(90).widthPercentage(100), field);
playfield.show();
}
//Build Drag and Drop
/*
public void drop(Component dragged, int x, int y) {
int i = playfield.getComponentIndex(dragged);
if(i > -1) {
Component dest = playfield.getComponentAt(x, y);
if(dest != dragged) {
int destIndex = playfield.getComponentIndex(dest);
if(destIndex > -1 && destIndex != i) {
// playfield.setComponentIndex(dragged,destIndex);
}
}
playfield.animateLayout(400);
} else {
Container oldParent = dragged.getParent();
if(oldParent != null) {
oldParent.removeComponent(dragged);
}
Component pos = playfield.getComponentAt(x, y);
i = playfield.getComponentIndex(pos);
if(i > -1) {
playfield.addComponent(i, dragged);
} else {
playfield.addComponent(dragged);
}
playfield.getComponentForm().animateHierarchy(400);
}
}
*/
}
我刚刚尝试了您的代码的这种变体:
TableLayout t2 = new TableLayout(2, 1);
Form playfield = new Form(t2);
Container controls = new Container();
Container field = new Container();
field.getAllStyles().setBgColor(0xff);
field.getAllStyles().setBgTransparency(0xff);
playfield.add(t2.createConstraint().heightPercentage(10).widthPercentage(100), controls);
playfield.add(t2.createConstraint().heightPercentage(90).widthPercentage(100), field);
playfield.show();
它没有滚动到一边或有任何我能看到的问题。它在功能上应该是相同的。您能否提供屏幕截图或视频来说明您所看到的内容?