黑莓如何设计像网格视图画面 [英] Blackberry how to design the Screen like grid view

查看:401
本文介绍了黑莓如何设计像网格视图画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的黑莓开发,我甚至不知道如何下手。我已经读过它的某些部分从它的官方网站

I am very new to blackberry development and i don't even know how to start. I already read some part of it from it's official site

<一个href=\"http://developer.blackberry.com/devzone/files/design/bb7/UI_Guidelines_BlackBerry_Smartphones_7_1.pdf\" rel=\"nofollow\">http://developer.blackberry.com/devzone/files/design/bb7/UI_Guidelines_BlackBerry_Smartphones_7_1.pdf

和其他许多环节,但因为它是说大公如果要发布更多的链接,那么你必须有10声誉和我没有我不能发布所有的链接,对于很抱歉,

and other so many link, but i can not post all the link as it is saying thay if you want to post more links then you must have 10 reputation and i dont have that so sorry for that,

现在我的问题是我想设计布局像这样 http://postimg.org/image/we3leycsd/

Now my question is i want to design layout like this http://postimg.org/image/we3leycsd/

我如何设计正是这种布局。我使用的Eclipse为黑莓开发。

How can i design exactly this kind of layout. I am using eclipse for Blackberry development.

请帮我已经尝试过很多事情,但我不能够实现这一目标。

Please help i already tried many things but i am not able to achieve this.

您任何形式的帮助将是AP preciated。谢谢你在前进。

Your any kind of help would be appreciated. Thank you in advance.

推荐答案

我想创建一个自定义的 Horizo​​ntalFieldManager 有n VerticalFieldManager 里面装的,然后覆盖添加删除方法。下面是我之前提出的,应该为你工作,它增加了新的领域,以最短的栏位。

I'd create a custom HorizontalFieldManager with n VerticalFieldManagers inside, then override the add and delete methods. Here is something I made before, that should work for you, it adds the new fields to the shortest column.

StaggeredListView.java:

StaggeredListView.java:

public class StaggeredListView extends HorizontalFieldManager
{
    private int column_spacing = 0;

    public StaggeredListView(int columns)
    {
        super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR | NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR | USE_ALL_WIDTH);

        if (columns < 1)
        {
            throw new RuntimeException("Number of columns needs to be larger than 0.");
        }

        final int width = Display.getWidth() / columns;

        for (int i = 0; i < columns; i++)
        {
            VerticalFieldManager vfm = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR | NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR)
            {
                protected void sublayout(int maxWidth, int maxHeight)
                {
                    maxWidth = Math.min(width, getPreferredWidth());
                    maxHeight = Math.min(maxHeight, getPreferredHeight());
                    super.sublayout(width, maxHeight);
                    super.setExtent(width, maxHeight);
                }
            };
            super.add(vfm);
        }
    }

    public int getColumnCount()
    {
        return getFieldCount();
    }

    /**
     * Sets the spacing between columns.
     * 
     * <p>
     * Spacing between fields is <i><b>not</b></i> set.
     * </p>
     */
    public void setColumnSpacing(int spacing)
    {
        if (spacing < 0) throw new RuntimeException("Column spacing my not be negative.");

        int length = getColumnCount();
        for (int i = 1; i < length; i++)
        {
            ((VerticalFieldManager) getField(i)).setPadding(0, 0, 0, spacing);
        }

        column_spacing = spacing;
    }

    /**
     * Get the value currently assigned via the {@link #setColumnSpacing(int)} method.
     * 
     * @return
     */
    public int getColumnSpacing()
    {
        return column_spacing;
    }

    /**
     * Deletes all fields from each of the columns.
     */
    public void clear()
    {
        int length = getColumnCount();
        for (int i = 0; i < length; i++)
        {
            ((VerticalFieldManager) getField(i)).deleteAll();
        }
    }

    /**
     * Delete specified field from the columns.
     * 
     * <p>
     * Does <b><i>not</i></b> rearrange fields.
     * </p>
     */
    public void delete(Field field)
    {
        int length = getColumnCount();
        for (int i = 0; i < length; i++)
        {
            try
            {
                ((VerticalFieldManager) getField(i)).delete(field);
                break;
            } catch (IllegalArgumentException e)
            {
                // field not in this manager
            }
        }
    }

    /**
     * Adds the field to the column with the least height.
     */
    public void add(Field field)
    {
        // find the vfm with least height
        int index = 0;
        int height = ((VerticalFieldManager) getField(index)).getPreferredHeight();

        int length = getColumnCount();
        for (int i = 1; i < length; i++)
        {
            int temp_height = ((VerticalFieldManager) getField(i)).getPreferredHeight();
            if (temp_height < height)
            {
                height = temp_height;
                index = i;
            }
        }

        ((VerticalFieldManager) getField(index)).add(field);
    }
}

至于其中包含的项目的,我想创建一个字段的图像和文字,然后画它自己(我有很多问题的重点,并发现它更容易只是用油漆)。
您可以使用此作的BaseButton http://developer.blackberry.com/bbos/java/documentation/tutorial_create_custom_button_1969896_11.html

BaseButton.java:

BaseButton.java:

public abstract class BaseButton extends Field
{
    // flags to indicate the current visual state
    protected boolean _visible = true;
    protected boolean _active;
    protected boolean _focus;

    protected boolean drawfocus = false;

    private int touch_top = 0;
    private int touch_right = 0;
    private int touch_bottom = 0;
    private int touch_left = 0;

    protected boolean fire_on_click = true; // false fires on unclick

    public BaseButton()
    {
        this(0);
    }

    public BaseButton(long style)
    {
        super((style & Field.NON_FOCUSABLE) == Field.NON_FOCUSABLE ? style : style | Field.FOCUSABLE);
    }

    /**
     * Sets the radius around the button to trigger touch events.
     * <p>
     * (0,0,0,0) by default.
     * </p>
     */
    public void setTouchRadius(int top, int right, int bottom, int left)
    {
        touch_top = top;
        touch_right = right;
        touch_bottom = bottom;
        touch_left = left;
    }

    protected void onFocus(int direction)
    {
        _focus = true;
        invalidate();
        super.onFocus(direction);
    }

    protected void onUnfocus()
    {
        if (_active || _focus)
        {
            _focus = false;
            _active = false;
            invalidate();
        }
        super.onUnfocus();
    }

    public void set_visible(boolean visible)
    {
        _visible = visible;
        invalidate();
    }

    public boolean is_visible()
    {
        return _visible;
    }

    protected void drawFocus(Graphics g, boolean on)
    {
        if (drawfocus) super.drawFocus(g, on);
    }

    protected void layout(int width, int height)
    {
        setExtent(Math.min(width, getPreferredWidth()), Math.min(height, getPreferredHeight()));
    }

    protected boolean keyUp(int keycode, int time)
    {
        if (Keypad.map(Keypad.key(keycode), Keypad.status(keycode)) == Characters.ENTER)
        {
            _active = false;
            invalidate();
            return true;
        }

        return false;
    }

    protected boolean keyDown(int keycode, int time)
    {
        if (Keypad.map(Keypad.key(keycode), Keypad.status(keycode)) == Characters.ENTER)
        {
            _active = true;
            invalidate();
        }

        return super.keyDown(keycode, time);
    }

    protected boolean keyChar(char character, int status, int time)
    {
        if (character == Characters.ENTER)
        {
            clickButton();
            return true;
        }

        return super.keyChar(character, status, time);
    }

    protected boolean navigationClick(int status, int time)
    {
        if (status != 0)
        { // non-touch event
            _active = true;
            invalidate();
            if (fire_on_click) clickButton();
        }
        return true;
    }

    protected boolean trackwheelClick(int status, int time)
    {
        if (status != 0)
        { // non-touch event
            _active = true;
            invalidate();
            if (fire_on_click) clickButton();
        }
        return true;
    }

    protected boolean navigationUnclick(int status, int time)
    {
        if (status != 0)
        { // non-touch event
            _active = false;
            invalidate();
            if (!fire_on_click) clickButton();
        }
        return true;
    }

    protected boolean trackwheelUnclick(int status, int time)
    {
        if (status != 0)
        { // non-touch event
            _active = false;
            invalidate();
            if (!fire_on_click) clickButton();
        }
        return true;
    }

    protected boolean invokeAction(int action)
    {
        switch (action)
        {
            case ACTION_INVOKE :
            {
                clickButton();
                return true;
            }
        }

        return super.invokeAction(action);
    }

    protected boolean touchEvent(TouchEvent message)
    {
        boolean isOutOfBounds = touchEventOutOfBounds(message);
        switch (message.getEvent())
        {
            case TouchEvent.CLICK :
                if (!_active)
                {
                    _active = true;
                    invalidate();
                }

                if (!isOutOfBounds)
                {
                    if (fire_on_click) clickButton();
                    return true;
                }

            case TouchEvent.DOWN :
                if (!isOutOfBounds)
                {
                    if (!_active)
                    {
                        _active = true;
                        invalidate();
                    }
                    return true;
                }
                return false;

            case TouchEvent.UNCLICK :
                if (_active)
                {
                    _active = false;
                    invalidate();
                }

                if (!isOutOfBounds)
                {
                    if (!fire_on_click) clickButton();
                    return true;
                }

            case TouchEvent.UP :
                if (_active)
                {
                    _active = false;
                    invalidate();
                }

            default :
                return false;
        }
    }

    private boolean touchEventOutOfBounds(TouchEvent message)
    {
        int x = message.getX(1);
        int y = message.getY(1);
        return (x < 0 - touch_left || y < 0 - touch_top || x > getWidth() + touch_right || y > getHeight() + touch_bottom);
    }

    public void setDirty(boolean dirty)
    {
    }

    public void setMuddy(boolean muddy)
    {
    }

    public void clickButton()
    {
        if (_visible) fieldChangeNotify(0);
    }
}

ImageSubtitleButton.java:

ImageSubtitleButton.java:

public class ImageSubtitleButton extends BaseButton
{
    private static final int FOCUS_THINKNESS = 2;
    String title;
    Bitmap image_default;

    int height;

    public ImageSubtitleButton(String title, String image_default)
    {
        this.image_default = Bitmap.getBitmapResource(image_default);
        setTitle(title);
    }

    public void setTitle(String title)
    {
        this.title =  title;
        height = image_default.getHeight() + getFont().getHeight()  + (FOCUS_THINKNESS * 2);

        updateLayout();
        invalidate();
    }

    public int getPreferredWidth()
    {
        return Math.max(getFont().getAdvance(title), image_default.getWidth());
    }

    public int getPreferredHeight()
    {
        return height;
    }

    protected void paint(Graphics graphics)
    {
        int x = (getWidth() - image_default.getWidth()) / 2;
        int y = 0;
        graphics.drawBitmap(x, y, image_default.getWidth(), image_default.getHeight(), image_default, 0, 0);

        if (_focus)
        {
            graphics.setColor(Color.BLUE); // your focus colour
            for (int i = 0; i < FOCUS_THINKNESS; i++)
            {
                graphics.drawRect(x + i, y + i, image_default.getWidth() - (i * 2), image_default.getHeight() - (i * 2));
            }
        }

        graphics.setColor(Color.BLACK);
        y = image_default.getHeight();
            graphics.drawText(title, x, y);
    }
}

现在您可以按以下这些添加到您的屏幕:

Now you can add these to your screen as follows:

StaggedListView listview = new StaggedListView(2);
ImageSubtitleButton button = new ImageSubtitleButton("test", "test.png");
listview.add(button);
add(listview);

您需要设置的preferred宽度和高度 ImageSubtitleButton 来保持均匀,为您发布的例子形象。

You'll need to set the preferred width and height of the ImageSubtitleButton to keep it uniform, as in the example image you posted.

这篇关于黑莓如何设计像网格视图画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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