Codename One拖动的容器迅速消失

huangapple go评论118阅读模式
英文:

Codename One dragged-over container quickly dissappears

问题

  1. 我有一个使用拖放操作的Android应用程序我并不经常使用拖放操作所以我刚开始学习它们的工作原理以及可能的影响
  2. 在我的应用程序中无论何时我将组件放在目标上方目标会出现一种闪烁的效果意味着它会在短暂的时刻内消失然后再次出现
  3. 这里是一个[链接][1]展示了应用程序的当前阶段
  4. 我猜这可能是由于表单的动画效果如果是这样我应该如何禁用它或者阻止目标闪烁
  5. 以下是我的代码由于我刚开始着手这个项目代码还很基础
  6. ```java
  7. public void testDrag () {
  8. Container containerDropTarget = new Container();
  9. Container container = new Container(new GridLayout(5,1));
  10. Label label = new Label("test test test test test test");
  11. Button buttonTwo = new Button("Test");
  12. buttonTwo.addDragOverListener(l-> {
  13. containerDropTarget.setUIID("DialogTest");
  14. });
  15. containerDropTarget.setUIID("LetterHolder");
  16. buttonTwo.setDraggable(true);
  17. containerDropTarget.setDropTarget(true);
  18. container.add(label).add(containerDropTarget);
  19. form.add(container).add(buttonTwo);
  20. form.show();
  21. }
英文:

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.

  1. public void testDrag () {
  2. Container containerDropTarget = new Container();
  3. Container container = new Container(new GridLayout(5,1));
  4. Label label = new Label("test test test test test test");
  5. Button buttonTwo = new Button("Test");
  6. buttonTwo.addDragOverListener(l-> {
  7. containerDropTarget.setUIID("DialogTest");
  8. });
  9. containerDropTarget.setUIID("LetterHolder");
  10. buttonTwo.setDraggable(true);
  11. containerDropTarget.setDropTarget(true);
  12. container.add(label).add(containerDropTarget);
  13. form.add(container).add(buttonTwo);
  14. form.show();
  15. }

答案1

得分: 1

我没有定义UIIDs,所以我使用了基于您的测试案例的这段代码,并且它正常工作。我还向拖放容器添加了一个标签,以便可以找到它:

  1. Container containerDropTarget = new Container() {
  2. @Override
  3. public void drop(Component dragged, int x, int y) {
  4. super.drop(dragged, x, y);
  5. setUIID("Container");
  6. }
  7. };
  8. containerDropTarget.add(new Label("Drop Target"));
  9. Form form = new Form("Test Drag", BoxLayout.y());
  10. Container container = new Container(new GridLayout(5,1));
  11. Label label = new Label("test test test test test test");
  12. Button buttonTwo = new Button("Test");
  13. buttonTwo.addDragOverListener(l-> {
  14. //containerDropTarget.setUIID("DialogTest");
  15. containerDropTarget.getAllStyles().setBgColor(0xff0000);
  16. containerDropTarget.getAllStyles().setBgTransparency(0xff);
  17. containerDropTarget.repaint();
  18. });
  19. containerDropTarget.setUIID("LetterHolder");
  20. buttonTwo.setDraggable(true);
  21. containerDropTarget.setDropTarget(true);
  22. container.add(label).add(containerDropTarget);
  23. form.add(container).add(buttonTwo);
  24. 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:

  1. Container containerDropTarget = new Container() {
  2. @Override
  3. public void drop(Component dragged, int x, int y) {
  4. super.drop(dragged, x, y);
  5. setUIID("Container");
  6. }
  7. };
  8. containerDropTarget.add(new Label("Drop Target"));
  9. Form form = new Form("Test Drag", BoxLayout.y());
  10. Container container = new Container(new GridLayout(5,1));
  11. Label label = new Label("test test test test test test");
  12. Button buttonTwo = new Button("Test");
  13. buttonTwo.addDragOverListener(l-> {
  14. //containerDropTarget.setUIID("DialogTest");
  15. containerDropTarget.getAllStyles().setBgColor(0xff0000);
  16. containerDropTarget.getAllStyles().setBgTransparency(0xff);
  17. containerDropTarget.repaint();
  18. });
  19. containerDropTarget.setUIID("LetterHolder");
  20. buttonTwo.setDraggable(true);
  21. containerDropTarget.setDropTarget(true);
  22. container.add(label).add(containerDropTarget);
  23. form.add(container).add(buttonTwo);
  24. form.show();

huangapple
  • 本文由 发表于 2020年9月17日 03:51:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63927093.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定