LWUIT textarea滚动问题 [英] LWUIT textarea scroll issue

查看:70
本文介绍了LWUIT textarea滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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滚动基于当前组件的焦点进行工作.因此,当您按下向下箭头时,焦点将切换到下面的元素,并且在必要时滚动窗体.标签默认情况下无法聚焦,因此它们将不会获得焦点,并且滚动将无法正常工作.要解决此问题,您应该修改标签的创建.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆