Codenameone 如何正确实施修复,使向下拖动隐藏组件起作用?

Codenameone 如何正确实施修复,使向下拖动隐藏组件起作用?,codenameone,Codenameone,当某个组件被隐藏时,其高度将强制为0,这将阻止向下拖动时在组件中滚动。基本上,它可以被拖到屏幕的边缘,但不会向下滚动。这一问题在前面的SO中也提到过,Shai为调查提供了途径 有什么建议可以解决这个问题吗 谢谢 下面是一个代码示例,用于重现该问题(复制/粘贴到Hello World项目中,以替换默认的start()方法): imagedragimage2; 组件放置占位符; 无效保存dragIm(图像dragIm){ dragImage2=dragIm; } 公开作废开始(){ 如果(当前!=n

当某个组件被隐藏时,其高度将强制为0,这将阻止向下拖动时在
组件中滚动。基本上,它可以被拖到屏幕的边缘,但不会向下滚动。这一问题在前面的SO中也提到过,Shai为调查提供了途径

有什么建议可以解决这个问题吗

谢谢

下面是一个代码示例,用于重现该问题(复制/粘贴到Hello World项目中,以替换默认的
start()
方法):

imagedragimage2;
组件放置占位符;
无效保存dragIm(图像dragIm){
dragImage2=dragIm;
}
公开作废开始(){
如果(当前!=null){
current.show();
返回;
}
/*查看问题:按住按钮约1秒以启动拖放,
然后向下拖动到屏幕的下边缘:列表不会像往常一样向下滚动。
在列表中向上拖动时(当然必须向下滚动一点),
它按预期工作:当拖动的按钮到达屏幕顶部时,列表向下滚动*/
Form hi=新表单(“hi World”,new BorderLayout());
dropPlaceholder=new Label(“…”;//用于在放置位置创建空白
dropPlaceholder.setDropTarget(true);
Container list3=新容器(BoxLayout.y());
对于(int i=0;i<30;i++){
按钮DragTableButton=新按钮(“按钮编号”+i){
@凌驾
公共无效长指针压力(整数x,整数y){
可设置的(真);
设置聚焦(真);
dragImage2=super.getDragImage();
setHidden(true);
Form f=getComponentForm();
f、 点压缩(x,y);
pointerDraged(x-1,y-1);//将被拖动的元素移动几个像素以开始拖动
指针参差不齐(x-2,y-2);
}
@凌驾
受保护的图像GetDragage(){
返回dragImage2;
}
@凌驾
受保护的空拖曳完成(整数x,整数y){
setHidden(假);
if(dropPlaceholder!=null)
dropPlaceholder.remove();//拖动后删除占位符
}
};
DragableButton.setDropTarget(真);
DragableButton.addDragOverListener((e)->{
Component dropTarget=e.getDropTarget();//可能为null(在Component.dragFinishedImpl(int x,int y)中)
if(dropTarget!=null){
容器父级=dropTarget.getParent();
int index=parent.getComponentIndex(dropTarget);
dropPlaceholder.remove();//从上一个位置删除占位符
parent.addComponent(index,dropPlaceholder);//在dropTarget的位置添加占位符
}
getCurrentForm().revalidate();//刷新屏幕以显示占位符的新位置
});
列表3.添加(DragTableButton);
}
清单3.setScrollableY(真);
容器cont=hi.getContentPane();
继续添加(BorderLayout.CENTER,列表3);
嗨,show();
}

这种攻击是错误的,您只需粘贴一个硬编码值来解决您遇到的特定问题,我还没有看到测试用例。如果组件小于屏幕大小,滚动将停止工作。我建议创建一个测试用例,而不是专注于解决方法是的,这只是一个黑客行为:-)我在上面添加了一个测试用例来重现这个问题(很抱歉,这花费了一点时间,因为实际的代码处理了很多我需要删除的细节)。我无法理解代码,代码太多了。您需要简化此操作。感谢您的跟进。你可以忽略文章底部“试图解决问题”下面的代码——我只是保留了原始文本,但是,我认为我不能减少文章顶部的代码,因为这说明了问题。它需要相当多的运动部件来制作一些能够显示我所追求的拖放效果的东西(在拖动组件下方的空白处可以直观地显示它将被插入的位置)。要复制,只需复制到Hello World中,长按一个按钮并向下拖动即可。我意识到我第一个复制代码的示例引用了我没有包含的内容。这个版本经过了改进,希望能简化到更容易理解的程度。内联注释解释了如何重现问题。请注意,拖动是在长按上启动的,以便在同一个列表中结合滚动和拖放。这种方法是错误的,您只需粘贴一个硬编码值来解决您遇到的特定问题,而我还没有看到测试用例。如果组件小于屏幕大小,滚动将停止工作。我建议创建一个测试用例,而不是专注于解决方法是的,这只是一个黑客行为:-)我在上面添加了一个测试用例来重现这个问题(很抱歉,这花费了一点时间,因为实际的代码处理了很多我需要删除的细节)。我无法理解代码,代码太多了。您需要简化此操作。感谢您的跟进。你可以忽略文章底部“试图解决问题”下面的代码——我只是保留了原始文本,但是,我认为我不能减少文章顶部的代码,因为这说明了问题。它需要相当多的运动部件来制作一些能够显示我所追求的拖放效果的东西(在拖动组件下方的空白处可以直观地显示它将被插入的位置)。要复制,只需复制到Hello World中,长按一个按钮并向下拖动即可。我意识到我第一个复制代码的示例引用了我没有包含的内容。这个版本经过了改进,希望能简化到足够的程度
Image dragImage2;
Component dropPlaceholder;

void saveDragImage(Image dragIm) {
    dragImage2 = dragIm;
}

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    /* To seee the issue: press and hold a button about 1 second to initiate the drag and drop, 
    then drag down to the lower edge of the screen: the list doesn't scroll down as normally. 

    When dragging upwards in a list (which must of course alreaday be scrolled down a bit), 
    it works as expected: When the dragged button reaches to top of the screen, the list scrolls down. */

    Form hi = new Form("Hi World", new BorderLayout());
    dropPlaceholder = new Label(" ... "); //used to create an empty space in the drop position
    dropPlaceholder.setDropTarget(true);

    Container list3 = new Container(BoxLayout.y());
    for (int i = 0; i < 30; i++) {

        Button draggableButton = new Button("Button number " + i) {
            @Override
            public void longPointerPress(int x, int y) {
                setDraggable(true);
                setFocusable(true);
                dragImage2 = super.getDragImage();
                setHidden(true);
                Form f = getComponentForm();
                f.pointerPressed(x, y);
                pointerDragged(x - 1, y - 1); //move the dragged element a few pixels to initiate the drag
                pointerDragged(x - 2, y - 2);
            }

            @Override
            protected Image getDragImage() {
                return dragImage2;
            }

            @Override
            protected void dragFinished(int x, int y) {
                setHidden(false);
                if (dropPlaceholder != null)
                    dropPlaceholder.remove(); //remove the placeholder after drag
            }
        };
        draggableButton.setDropTarget(true);

        draggableButton.addDragOverListener((e) -> {
            Component dropTarget = e.getDropTarget(); //may be null (in Component.dragFinishedImpl(int x, int y))
            if (dropTarget != null) {
                Container parent = dropTarget.getParent();
                int index = parent.getComponentIndex(dropTarget);
                dropPlaceholder.remove(); //remove placeholder from previous position
                parent.addComponent(index, dropPlaceholder); //add placeholder at position of dropTarget
            }
            getCurrentForm().revalidate(); //refresh the screen to show the new position of placeholder
        });
        list3.add(draggableButton);
    }
    list3.setScrollableY(true);
    Container cont = hi.getContentPane();
    cont.add(BorderLayout.CENTER, list3);
    hi.show();
}