2017-07-21 36 views
1

这里是代码示例来面对我的问题。Codename One - 有没有办法避免点击时更改Button的UIID?

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 选择未被选择按压样式是相等的。

问题描述:

  1. 滚动content向下
  2. 调用lock()
  3. 点击contentlockButton截距点击)
  4. 当按下指针content的滚动是0,上释放,它返回到之前的金额。

我想这会发生,因为按钮更改它是单击样式,这会导致重新绘制/重新验证基础内容的错误。

根据钻石的回答

信息更新:

集装箱masterSwipeableContainer中心部分。

无论何时打开SwipeableContainer,都会调用方法lock()

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

也许是显著 - 有集装箱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); 
} 
+0

我发现这个问题很难从描述中理解。但是这里有几件事我可以说。按钮不会更改UIID。样式更改不会重新验证或影响滚动。一些截图或视频可以用来解释什么很快解释 –

+0

感谢您的关注,我会尽可能快地提供视频。 –

+0

这件事只发生在模拟器上,在设备上一切都很完美。抱歉。 –

回答

2

的问题是,当你调用lock()重新确认没有发生,从而lockButton没有正确摆出来,这只是正常,当你点击master容器的任何部分定位(滚动不适用)。

解决的办法是在主要的用户界面改变之后总是调用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(); 
} 
+0

请检查我的更改。 –

0

这只发生在模拟器中。在真实的设备上,一切都很好。抱歉。

相关问题