【问题标题】:Codename One - Is there a way to avoid changing Button's UIID on click?代号一 - 有没有办法避免在点击时更改按钮的 UIID?
【发布时间】:2017-07-23 20:26:38
【问题描述】:

这是解决我的问题的代码示例。

Container master, content;
Button lockButton;
void layout () {
    master = new Container (new LayeredLayout ());
    content = new Container (BoxLayout.y());
    content.setScrollableY (true);
    lockButton = new Button ("");
    lockButton.setUIID ("ButtonInvisible");
    lockButton.addActionListener ((e)->{
        unlock ();
    });
    master.add(content);
}
void lock () {
    master.add(lockButton);
}
void unlock () {
    lockButton.remove ();
}

ButtonInvisible selectedunselectedpressed 样式是相等的。

问题描述:

  1. 向下滚动content
  2. 调用lock()
  3. 点击contentlockButton拦截点击)
  4. 当指针被按下时content 的滚动为 0,释放时它返回到之前的量。

我猜这是因为 Button 在点击时改变了它的样式,这会导致底层内容的重新绘制/重新验证错误。

根据 Diamond 的回答更新

其他信息

容器masterSwipeableContainer 的中心部分。

只要打开SwipeableContainer,就会调用方法lock()

如果我在SwipeableContainer 打开时调用revalidate() - 屏幕奇怪地闪烁,但行为没有改变 - 每当按下按钮时,滚动仍然跳到零。

也许这很重要 - 容器 content 中有 Tabs 组件

在这个版本的代码重新验证不能成为此类问题的原因,因为没有添加或删除组件,但问题仍然存在。

Container master, content;
Button lockButton;
void layout () {
    master = new Container (new LayeredLayout ());
    content = new Container (BoxLayout.y());
    content.setScrollableY (true);
    lockButton = new Button ("");
    lockButton.setUIID ("ButtonInvisible");
    lockButton.addActionListener ((e)->{
        unlock ();
    });
    lockButton.setFocusable(false);
    master.add(content).add(lockButton);
}
void lock () {
    lockButton.setFocusable(true);
}
void unlock () {
    swipeableContainer.close ();
    lockButton.setFocusable(false);
}

【问题讨论】:

  • 我发现从描述中很难理解这个问题。但这里有几件事我可以说。按钮不会更改 UIID。样式更改不会重新验证或影响滚动。几张截图或一段视频可以很好地解释发生了什么
  • 感谢您的关注,我会尽快提供视频。
  • 这件事只发生在模拟器中,在设备上一切都是完美的。对不起。

标签: codenameone


【解决方案1】:

问题在于,当您调用 lock() 时没有发生重新验证,因此 lockButton 的布局不正确,只有当您单击 master 容器的任何部分时它才会正确定位(滚动不会' t 申请)。

解决方案是在 UI 发生重大变化(例如在容器中添加和移除组件)后始终调用 repaint()/revalidate() 或某种动画。

Container master, content;
Button lockButton;
void layout () {
    master = new Container (new LayeredLayout ());
    content = new Container (BoxLayout.y());
    content.setScrollableY (true);
    lockButton = new Button ("");
    lockButton.setUIID ("ButtonInvisible");
    lockButton.addActionListener ((e)->{
        unlock ();
    });
    master.add(content);
    master.revalidate();
}
void lock () {
    master.add(lockButton);
    master.revalidate();
}
void unlock () {
    lockButton.remove();
    master.revalidate();
}

【讨论】:

  • 请检查我的更改。
【解决方案2】:

这只发生在模拟器中。在真实设备上一切正常。对不起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    相关资源
    最近更新 更多