英文:
Codename One dragged-over container quickly dissappears
问题
我有一个使用拖放操作的Android应用程序。我并不经常使用拖放操作,所以我刚开始学习它们的工作原理以及可能的影响。
在我的应用程序中,无论何时我将组件放在目标上方,目标会出现一种“闪烁”的效果,意味着它会在短暂的时刻内消失,然后再次出现。
这里是一个[链接][1],展示了应用程序的当前阶段。
我猜这可能是由于表单的动画效果。如果是这样,我应该如何禁用它,或者阻止目标闪烁?
以下是我的代码。由于我刚开始着手这个项目,代码还很基础。
```java
public void testDrag () {
Container containerDropTarget = new Container();
Container container = new Container(new GridLayout(5,1));
Label label = new Label("test test test test test test");
Button buttonTwo = new Button("Test");
buttonTwo.addDragOverListener(l-> {
containerDropTarget.setUIID("DialogTest");
});
containerDropTarget.setUIID("LetterHolder");
buttonTwo.setDraggable(true);
containerDropTarget.setDropTarget(true);
container.add(label).add(containerDropTarget);
form.add(container).add(buttonTwo);
form.show();
}
英文:
I have an Android application that uses drag and drop operations. I haven't used drag and drop often, so I am just starting to learn how they work and what the implications might be.
In my app, whenever I drop the component over the target, the target sort of "flashes", meaning it disappears for a brief moment and than reappears again.
Here a link to the video with the app in its current stage.
I suppose this is due to the animation of the form. If so, how can I disable it, or stop the target from flashing?
Below is my code. It is still rudimentary, since I just started to work on the project.
public void testDrag () {
Container containerDropTarget = new Container();
Container container = new Container(new GridLayout(5,1));
Label label = new Label("test test test test test test");
Button buttonTwo = new Button("Test");
buttonTwo.addDragOverListener(l-> {
containerDropTarget.setUIID("DialogTest");
});
containerDropTarget.setUIID("LetterHolder");
buttonTwo.setDraggable(true);
containerDropTarget.setDropTarget(true);
container.add(label).add(containerDropTarget);
form.add(container).add(buttonTwo);
form.show();
}
答案1
得分: 1
我没有定义UIIDs,所以我使用了基于您的测试案例的这段代码,并且它正常工作。我还向拖放容器添加了一个标签,以便可以找到它:
Container containerDropTarget = new Container() {
@Override
public void drop(Component dragged, int x, int y) {
super.drop(dragged, x, y);
setUIID("Container");
}
};
containerDropTarget.add(new Label("Drop Target"));
Form form = new Form("Test Drag", BoxLayout.y());
Container container = new Container(new GridLayout(5,1));
Label label = new Label("test test test test test test");
Button buttonTwo = new Button("Test");
buttonTwo.addDragOverListener(l-> {
//containerDropTarget.setUIID("DialogTest");
containerDropTarget.getAllStyles().setBgColor(0xff0000);
containerDropTarget.getAllStyles().setBgTransparency(0xff);
containerDropTarget.repaint();
});
containerDropTarget.setUIID("LetterHolder");
buttonTwo.setDraggable(true);
containerDropTarget.setDropTarget(true);
container.add(label).add(containerDropTarget);
form.add(container).add(buttonTwo);
form.show();
英文:
I don't have the UIIDs defined so I used this code based on your test case and it worked correctly. I also added a label to the drop container so it could be found:
Container containerDropTarget = new Container() {
@Override
public void drop(Component dragged, int x, int y) {
super.drop(dragged, x, y);
setUIID("Container");
}
};
containerDropTarget.add(new Label("Drop Target"));
Form form = new Form("Test Drag", BoxLayout.y());
Container container = new Container(new GridLayout(5,1));
Label label = new Label("test test test test test test");
Button buttonTwo = new Button("Test");
buttonTwo.addDragOverListener(l-> {
//containerDropTarget.setUIID("DialogTest");
containerDropTarget.getAllStyles().setBgColor(0xff0000);
containerDropTarget.getAllStyles().setBgTransparency(0xff);
containerDropTarget.repaint();
});
containerDropTarget.setUIID("LetterHolder");
buttonTwo.setDraggable(true);
containerDropTarget.setDropTarget(true);
container.add(label).add(containerDropTarget);
form.add(container).add(buttonTwo);
form.show();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论