Codename One拖动的容器迅速消失

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

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();

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:

确定