如何避免滑动 SwipeableContainer 也会在顶部容器中创建事件?

How to avoid that swiping a SwipeableContainer also creates an event in the top container?

当我在顶部容器(不是您通过滑动显示的底层容器)中有一个带按钮的 SwipeableContainer 时,向左滑动容器也会按下该按钮。

你能帮忙设置一下吗,这样 SwipeableContainer 就会处理点击而不会将其发送到按钮?

感谢您的帮助。

问题如下例所示:最常向左滑动也会触发点击 "Press to see details" 按钮,这会立即使 leftSwipeCont 消失,并且 hides/unhides "Hideable details"。

下面是代码示例(复制到 HelloWorld 示例中):

hi = new Form("Hi World", new BoxLayout(BoxLayout.Y_AXIS));
Container hideable = new Container();
hideable.add("Hideable details");
hideable.setHidden(true);
Container cont = new Container(new BorderLayout());
cont.add(BorderLayout.SOUTH, hideable);
Button button = new Button("Press me to see details"); //shouldn't be pressed when the container is just swiped!!
button.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent evt) {
        hideable.setHidden(!hideable.isHidden());
        hideable.animateLayout(300);
    }
});
cont.add(BorderLayout.CENTER, button);
Container leftSwipeCont = new Container();
leftSwipeCont.add(new Button("XX"));
SwipeableContainer swipe = new SwipeableContainer(leftSwipeCont, cont);
hi.add(swipe);
hi.show();

有点"black magic":

button.setAutoRelease(true);

默认情况下,如果您在按钮内拖动手指,它不会松开它,因为它假定您仍想按下它。这可以处理复杂的情况,例如在 none.

时检测拖动的过度敏感屏幕

但是,在这种情况下,我们需要代码不那么敏感。