LWUIT textarea滚动问题 [英] LWUIT textarea scroll issue
问题描述
我对LWUIT滚动有问题. 我有一个包含textarea和20个标签的表单.当滚动到底部时,它跳到顶部(如循环).对不起,我的英语不好:(
I have problem with LWUIT scroll. I have a form contain textarea and 20 labels. When it scroll to the bottom, it jump to the top (like cycle). Sorry for my bad english :(
这是我的代码
public class ScrollMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form mainForm = new Form("Scroll issue");
mainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextArea textArea = new TextArea("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
mainForm.addComponent(textArea);
for (int i = 0; i < 20; i++) {
mainForm.addComponent(new Label("This is label " + (i + 1)));
}
mainForm.setScrollable(true);
mainForm.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
推荐答案
LWUIT scrolling works based on the focus of the current component. So when you press the down arrow, the focus changes to the element below and, if necessary, the Form scrolls. Labels are not focusable by default, so they won't receive focus and the scrolling will not work correctly. To correct this you should modify the label creation.
Label l = new Label("This is label " + (i + 1));
l.setFocusable(true);
mainForm.addComponent(l);
此外,水平滚动阅读内容确实是很糟糕的用户体验,因此应禁止水平滚动.
Also, it is really bad user experience to scroll horizontally to read content, so you should forbid horizontal scrolling.
mainForm.setScrollableX(false);
mainForm.setScrollableY(true);
现在setCyclicFocus应该可以正常工作了.
Now setCyclicFocus should work without problems.
这篇关于LWUIT textarea滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!