var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20738293-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script')"/>
<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jutleo
    歡迎走進有風的地方~~
    posts - 63,  comments - 279,  trackbacks - 0
    如何自定義一個自己的UI組件?
    創建一個自定義UI,需要繼承自現有的組件或者直接繼承Field類,通常我們必須實現layout()和paint()方法用于顯示想要的UI界面。
    1. layout()方法可在手機屏幕上實現一個具有寬度和高度的區域,調用setExtent(width, height);實現。getPreferredWidth()、getPreferredHeight()告訴容器出現在屏幕上合適的高度和寬度
    public int getPreferredWidth() {
            
    return this.getScreen().getWidth() / 7;
        }

        
    /**
         * Gets the preferred height of the button.
         
    */
        
    public int getPreferredHeight() {
            
    return _labelHeight;
        }

        
    protected void layout(int width, int height) {
            
    // Calc width.
            width = getPreferredWidth();

            
    // Calc height.
            height =getPreferredHeight();

            
    // Set dimensions.
            setExtent(width, height);
        }
    2. paint()方法使用Graphics對象繪制UI,drawLine, drawRect,drawText
    protected void paint(Graphics graphics) {
    //        graphics.setColor(0xDDDDDD);
    //        graphics.fillRect( 0, 0, getWidth(), getHeight() );
            int textX, textY, textWidth;
            
    int w = getWidth();
            
    if (_isBorder == 0) {
                graphics.drawRect(
    00, w, getHeight());
            }
            textX 
    = 4;
            textY 
    = 2;
            textWidth 
    = w - 6;
            graphics.drawText(_label, textX, textY, (
    int) (getStyle() 
                    
    & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK), textWidth);
        }
    3. 如果要處理鍵盤和滾輪事件可以實現keyChar()/trackwheelClick()方法
    4. 如果在控件獲取到焦點,實現onFocus()方法,可查看黑莓自帶的例子
    貼上完整的代碼:CalenderField.java
    package org.bulktree.calender;

    import net.rim.device.api.ui.*;

    class CalenderField extends Field implements DrawStyle {
        
    public static final int RECTANGLE = 1;
        
    public static final int TRIANGLE = 2;
        
    public static final int OCTAGON = 3;

        
    private String _label;
        
    private Font _font;
        
    private int _labelHeight;
        
    private int _isBorder = 0;//是否有邊框0有1無
        
        
    public CalenderField(String label, int shape, long style) {
            
    super(style);
            _label 
    = label;
            _font 
    = getFont();
            _labelHeight 
    = _font.getHeight();
        }
        
        
    public CalenderField(String lable, int shape, long style, int isBorder) {
            
    super(style);
            _label 
    = lable;
            _font 
    = getFont();
            _labelHeight 
    = _font.getHeight();
            _isBorder 
    = isBorder;
        }

        
    /**
         * Gets the preferred width of the button.
         
    */
        
    public int getPreferredWidth() {
            
    return this.getScreen().getWidth() / 7;
        }

        
    /**
         * Gets the preferred height of the button.
         
    */
        
    public int getPreferredHeight() {
            
    return _labelHeight;
        }

        
    protected void layout(int width, int height) {
            
    // Calc width.
            width = getPreferredWidth();

            
    // Calc height.
            height =getPreferredHeight();

            
    // Set dimensions.
            setExtent(width, height);
        }

        
    protected void paint(Graphics graphics) {
    //        graphics.setColor(0xDDDDDD);
    //        graphics.fillRect( 0, 0, getWidth(), getHeight() );
            int textX, textY, textWidth;
            
    int w = getWidth();
            
    if (_isBorder == 0) {
                graphics.drawRect(
    00, w, getHeight());
            }
            textX 
    = 4;
            textY 
    = 2;
            textWidth 
    = w - 6;
            graphics.drawText(_label, textX, textY, (
    int) (getStyle() 
                    
    & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK), textWidth);
        }
    }
    posted on 2011-01-20 15:45 凌晨風 閱讀(1832) 評論(1)  編輯  收藏 所屬分類: BlackBerry

    FeedBack:
    # re: 黑莓開發學習入門系列,自己動手實現一個日歷軟件(五)
    2011-01-20 15:56 | 蒙奇奇
    沙發觀看  回復  更多評論
      

    <2011年1月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    常用鏈接

    留言簿(11)

    我參與的團隊

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    收藏夾

    圍脖

    最新隨筆

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: fc2免费人成为视频| 亚洲国产精品第一区二区| 国产午夜无码视频免费网站| 亚洲短视频男人的影院| 一个人看的在线免费视频| 成年性羞羞视频免费观看无限 | 91成人免费福利网站在线| 日韩一区二区三区免费体验| 亚洲av日韩av激情亚洲| 亚洲AV无码专区亚洲AV桃| 99热这里只有精品免费播放| 亚洲人成在线播放网站| 国内成人精品亚洲日本语音| 成人性生交大片免费看无遮挡| 亚洲av无码国产精品夜色午夜 | 免费看片免费播放| 亚洲伊人久久大香线焦| 少妇人妻偷人精品免费视频| 亚洲综合精品网站| 久久免费99精品国产自在现线| 国产成人aaa在线视频免费观看 | 国产zzjjzzjj视频全免费| 亚洲av无码专区在线观看下载| 国产亚洲情侣久久精品| 精品国产无限资源免费观看| 亚洲第一成年网站大全亚洲| 无码人妻精品中文字幕免费 | 在线日韩av永久免费观看| 国产午夜亚洲精品国产| 成人毛片视频免费网站观看| 亚洲aⅴ天堂av天堂无码麻豆| mm1313亚洲精品国产| a级成人免费毛片完整版| 亚洲色图.com| 免费精品国产自产拍观看| 久久国产美女免费观看精品| 亚洲精品视频久久| 免费一级毛片清高播放| 久久美女网站免费| 亚洲乱妇熟女爽到高潮的片| 亚洲国产精品一区二区第四页|