【问题标题】:Blackberry -- Listfield with transparent rows黑莓——具有透明行的列表字段
【发布时间】:2011-07-01 00:44:37
【问题描述】:

我有一个屏幕,其背景图像呈现如下:

     bg = new VerticalFieldManager(
            VerticalFieldManager.USE_ALL_WIDTH |
            VerticalFieldManager.USE_ALL_HEIGHT |
            VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR |
            VerticalFieldManager.NO_VERTICAL_SCROLLBAR |
            VerticalFieldManager.NO_HORIZONTAL_SCROLL |
            VerticalFieldManager.NO_VERTICAL_SCROLL) {
        //Override the paint method to draw the background image.
        public void paint(Graphics graphics) {
            //Draw the background image and then call paint.
            graphics.drawBitmap(Graphics.getScreenWidth()/2 - bgBitmap.getWidth()/2,
                    Graphics.getScreenHeight()/2 - bgBitmap.getHeight()/2, 
                    bgBitmap.getWidth(), bgBitmap.getHeight(), bgBitmap, 0, 0);
            super.paint(graphics);
        }
    };
    add(bg);

然后我将屏幕的任何字段添加到此管理器。我有一个想要查看背景的 ListField。首次渲染屏幕时,一切正常。我可以看到图像。只要我向下滚动,选择某些内容并取消选择它,背景就会消失(变成白色)。

在绘制列表行时是否需要做一些特别的事情,以便在选择颜色消失后使它们真正透明?

注意:我发现无论在背景上绘制什么字段都会发生这种情况。它会正确显示,直到为给定的可聚焦字段绘制选择颜色,然后您选择其他内容。取消选择后,所有被选择颜色填充的区域都变为默认的白色。

【问题讨论】:

    标签: blackberry


    【解决方案1】:

    在 onfocus() 和 onunfocus() 方法中使用 invalidate() 函数。

    例如,如果您使用 LabelField,则使用:

    LabelField l=new LabelField("Hello",FOCUSABLE)
            {
                protected void onFocus(int direction) 
                {
                    invalidate();
                    super.onFocus(direction);
                }
                protected void onUnfocus() 
                {
                    invalidate();
                    super.onUnfocus();
                }
            };
    

    【讨论】:

    • 首先,非常感谢!这个解决方案非常适合我的一些问题。我只认为 onUnfocus() 是必需的。我仍然遇到的问题是 ListField 行。我尝试为整个 ListField 以及用于包含列表行但没有骰子的单个 TableRowManager 对象覆盖 onUnfocus()。
    • 还需要在drawListRow()函数和paint()函数中调用invalidate()方法。实际上 invalidate() 方法需要在 UI 更改时调用。当任何领域获得焦点时,基本上它会绘制一个蓝色矩形,即 Ui 已更改。
    【解决方案2】:

    我最终在我的自定义 ListField 中覆盖了 moveFocus()。

        public int moveFocus(int amount, int status, int time) {
            invalidate(getSelectedIndex());
            return super.moveFocus(amount, status, time);
        }
    

    Vivek 的方法虽然适用于 ListField 行之外的单个字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多