通过拖动连续重新排序列表
Continuously Reordering A List By Dragging
我研究了拖放,发现 Container 的 drop 方法会打乱容器组件。
这让我问自己:如果在继续拖动的同时不断发生下降不是很好吗。
所以我就这样做了 - 只是它产生了奇怪的结果。显然是进入了被拖组件不再绘制的状态,释放指针时不调用被拖组件的dragFinished方法
请帮助我了解那里出了什么问题。
代码如下:
public class FormContinuousDrop extends Form {
private class LabelDraggable extends Label {
int pressedX = 0;
public LabelDraggable(String aCaption) {
super(aCaption);
setDraggable(true);
}
@Override
public void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
pressedX = x;
}
@Override
public void pointerDragged(int x, int y) {
Log.p("LabelDraggable.pointerDragged(" + x + ", " + y + ")");
super.pointerDragged(pressedX, y);
{ // Here is where the "list" is shuffled whilst remaining dragging
if (isDragActivated() && !getAnimationManager().isAnimating()) {
ContainerDropTarget containerDropTarget = (ContainerDropTarget) getParent();
containerDropTarget.drop(this, pressedX, getDraggedy());
}
}
}
@Override
protected void dragFinished(int x, int y) {
Log.p("LabelDraggable.dragFinished(" + x + ", " + y + ")");
super.dragFinished(x, y);
}
}
private class ContainerDropTarget extends Container {
public ContainerDropTarget() {
super(new BoxLayout(BoxLayout.Y_AXIS));
setDropTarget(true);
}
@Override
public Component getComponentAt(int x, int y) {
boolean edt = Display.getInstance().isEdt();
Log.p("ContainerDropTarget.getComponentAt(" + x + ", " + y + ") - EDT: " + String.valueOf(edt));
return super.getComponentAt(x, y);
}
@Override
public void drop(Component dragged, int x, int y) {
Log.p("ContainerDropTarget.drop(" + x + ", " + y + ")");
super.drop(dragged, x, y);
}
}
public FormContinuousDrop() {
setTitle("FormContinuousDrop");
setScrollable(false);
Container containerContent = getContentPane();
containerContent.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
containerContent.add(new SpanLabel("Simple Drag And Drop example where drop is done continously whilst dragging"));
ContainerDropTarget containerDropTarget = new ContainerDropTarget();
for (int tally = 0; tally < 20; tally++) {
containerDropTarget.add(new LabelDraggable("draggable " + (tally + 1)));
}
containerContent.add(containerDropTarget);
}
}
如果您有一些动画挂起,那么 remove/add 可能会创建一个动画并延迟诸如 removal/addition 之类的东西,以防止多个动画之间发生冲突。在 adding/removing.
之前,您应该始终检查组件的实际状态
好的,我尝试做的事情暂时无法完成,原因如下:
- 方法
com.codename1.ui.Container.drop(Component, int, int)
间接导致变量 Form.dragged
设置为零,进而导致拖动被中断 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1992
- 如果方法
com.codename1.ui.AnimationManager.isAnimating()
returns false 这并不意味着没有动画正在进行 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1993
com.codename1.ui.Component.dragFinishedImpl(int, int)
使用屏幕坐标滚动放置目标容器,这通常会导致可滚动容器出现奇怪的结果 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1994
很难找到上述问题的解决方法,因为通常只有私有或包私有访问存在,并且代号一不支持 类.
的遮蔽
另一方面,我觉得自己对 Codename One 不够熟悉,无法自己进行适当的更改,post 请求请求。
我研究了拖放,发现 Container 的 drop 方法会打乱容器组件。
这让我问自己:如果在继续拖动的同时不断发生下降不是很好吗。
所以我就这样做了 - 只是它产生了奇怪的结果。显然是进入了被拖组件不再绘制的状态,释放指针时不调用被拖组件的dragFinished方法
请帮助我了解那里出了什么问题。
代码如下:
public class FormContinuousDrop extends Form {
private class LabelDraggable extends Label {
int pressedX = 0;
public LabelDraggable(String aCaption) {
super(aCaption);
setDraggable(true);
}
@Override
public void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
pressedX = x;
}
@Override
public void pointerDragged(int x, int y) {
Log.p("LabelDraggable.pointerDragged(" + x + ", " + y + ")");
super.pointerDragged(pressedX, y);
{ // Here is where the "list" is shuffled whilst remaining dragging
if (isDragActivated() && !getAnimationManager().isAnimating()) {
ContainerDropTarget containerDropTarget = (ContainerDropTarget) getParent();
containerDropTarget.drop(this, pressedX, getDraggedy());
}
}
}
@Override
protected void dragFinished(int x, int y) {
Log.p("LabelDraggable.dragFinished(" + x + ", " + y + ")");
super.dragFinished(x, y);
}
}
private class ContainerDropTarget extends Container {
public ContainerDropTarget() {
super(new BoxLayout(BoxLayout.Y_AXIS));
setDropTarget(true);
}
@Override
public Component getComponentAt(int x, int y) {
boolean edt = Display.getInstance().isEdt();
Log.p("ContainerDropTarget.getComponentAt(" + x + ", " + y + ") - EDT: " + String.valueOf(edt));
return super.getComponentAt(x, y);
}
@Override
public void drop(Component dragged, int x, int y) {
Log.p("ContainerDropTarget.drop(" + x + ", " + y + ")");
super.drop(dragged, x, y);
}
}
public FormContinuousDrop() {
setTitle("FormContinuousDrop");
setScrollable(false);
Container containerContent = getContentPane();
containerContent.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
containerContent.add(new SpanLabel("Simple Drag And Drop example where drop is done continously whilst dragging"));
ContainerDropTarget containerDropTarget = new ContainerDropTarget();
for (int tally = 0; tally < 20; tally++) {
containerDropTarget.add(new LabelDraggable("draggable " + (tally + 1)));
}
containerContent.add(containerDropTarget);
}
}
如果您有一些动画挂起,那么 remove/add 可能会创建一个动画并延迟诸如 removal/addition 之类的东西,以防止多个动画之间发生冲突。在 adding/removing.
之前,您应该始终检查组件的实际状态好的,我尝试做的事情暂时无法完成,原因如下:
- 方法
com.codename1.ui.Container.drop(Component, int, int)
间接导致变量Form.dragged
设置为零,进而导致拖动被中断 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1992 - 如果方法
com.codename1.ui.AnimationManager.isAnimating()
returns false 这并不意味着没有动画正在进行 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1993 com.codename1.ui.Component.dragFinishedImpl(int, int)
使用屏幕坐标滚动放置目标容器,这通常会导致可滚动容器出现奇怪的结果 - 请参阅问题 https://github.com/codenameone/CodenameOne/issues/1994
很难找到上述问题的解决方法,因为通常只有私有或包私有访问存在,并且代号一不支持 类.
的遮蔽另一方面,我觉得自己对 Codename One 不够熟悉,无法自己进行适当的更改,post 请求请求。