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
    歡迎走進(jìn)有風(fēng)的地方~~
    posts - 63,  comments - 279,  trackbacks - 0
    如何自定義一個(gè)自己的UI組件?
    創(chuàng)建一個(gè)自定義UI,需要繼承自現(xiàn)有的組件或者直接繼承Field類,通常我們必須實(shí)現(xiàn)layout()和paint()方法用于顯示想要的UI界面。
    1. layout()方法可在手機(jī)屏幕上實(shí)現(xiàn)一個(gè)具有寬度和高度的區(qū)域,調(diào)用setExtent(width, height);實(shí)現(xiàn)。getPreferredWidth()、getPreferredHeight()告訴容器出現(xiàn)在屏幕上合適的高度和寬度
    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對(duì)象繪制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. 如果要處理鍵盤和滾輪事件可以實(shí)現(xiàn)keyChar()/trackwheelClick()方法
    4. 如果在控件獲取到焦點(diǎn),實(shí)現(xiàn)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無(wú)
        
        
    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 凌晨風(fēng) 閱讀(1830) 評(píng)論(1)  編輯  收藏 所屬分類: BlackBerry

    FeedBack:
    # re: 黑莓開(kāi)發(fā)學(xué)習(xí)入門系列,自己動(dòng)手實(shí)現(xiàn)一個(gè)日歷軟件(五)
    2011-01-20 15:56 | 蒙奇奇
    沙發(fā)觀看  回復(fù)  更多評(píng)論
      

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

    常用鏈接

    留言簿(11)

    我參與的團(tuán)隊(duì)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    收藏夾

    圍脖

    最新隨筆

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲成a人片在线观看精品| 波多野结衣在线免费观看| 亚洲丰满熟女一区二区哦| 久久亚洲私人国产精品| 亚洲熟妇中文字幕五十中出| 最新猫咪www免费人成| 日韩免费高清大片在线| 久久成人18免费网站| 日韩亚洲综合精品国产| 亚洲熟妇av午夜无码不卡| 亚洲成aⅴ人在线观看| 亚洲成AV人片在线观看无| 4338×亚洲全国最大色成网站| 免费观看美女裸体网站| 9久9久女女免费精品视频在线观看| 中文字幕无码免费久久| 三上悠亚在线观看免费| 一边摸一边桶一边脱免费视频| 日韩国产欧美亚洲v片| 亚洲精品无码专区在线播放| 热99RE久久精品这里都是精品免费| 亚洲欧美在线x视频| 亚洲av永久中文无码精品综合| 亚洲AV成人噜噜无码网站| 亚洲永久中文字幕在线| 中文字幕亚洲综合久久| 久久久久亚洲AV成人无码| 亚洲国产精品无码久久久不卡| 国产亚洲人成A在线V网站| 久久久久国产成人精品亚洲午夜| 亚洲AV成人潮喷综合网| 免费国产叼嘿视频大全网站| 国产精品hd免费观看| a级毛片免费高清视频| 精品国产呦系列在线观看免费| 一边摸一边桶一边脱免费视频| 国产无限免费观看黄网站| 日本卡1卡2卡三卡免费| 在线a免费观看最新网站| 91网站免费观看| 日韩免费无砖专区2020狼|