BlackBerry開(kāi)發(fā)實(shí)現(xiàn)類似Lwuit的Tabbed Pane效果
本文和大家重點(diǎn)學(xué)習(xí)一下Black Berry開(kāi)發(fā)實(shí)現(xiàn)類似Lwuit的Tabbed Pane效果,Lwuit雖然有Black Berry的版本,它將所有版本的包括QWERTY、suretype、touch等的不同系統(tǒng)版本混合到一起,給裁剪帶來(lái)很大難度。
BlackBerry開(kāi)發(fā)實(shí)現(xiàn)類似Lwuit的TabbedPane效果
Lwuit雖然有BlackBerry開(kāi)發(fā)的版本,但是對(duì)其源代碼進(jìn)行分析過(guò)后才發(fā)現(xiàn)并不能直接應(yīng)用于實(shí)際項(xiàng)目中,它將所有版本的包括QWERTY、suretype、touch等的不同系統(tǒng)版本混合到一起,給裁剪帶來(lái)很大難度。目前對(duì)其設(shè)計(jì)結(jié)構(gòu)并不十分明確,所以源代碼的裁剪過(guò)程比較混亂。雖然blackberryUI不提供類似Lwuit的分頁(yè)效果,但是我們可以利用現(xiàn)有的API簡(jiǎn)單的模仿。等一些目前棘手的問(wèn)題解決后,再慢慢研究吧。。。
兩種實(shí)現(xiàn)方法:
1、使用屏幕Screen切換;
2、使用Graphics封裝。
這兩種方法都要用到滾輪的navigationMovement()事件響應(yīng)函數(shù),所以必須在需要切換的屏幕中重寫(xiě)這個(gè)事件。
◆實(shí)現(xiàn)一:使用屏幕Screen切換
思路:在UiApplication的構(gòu)造函數(shù)中先將這兩個(gè)屏幕壓入堆棧。然后創(chuàng)建兩個(gè)Sreen,在每個(gè)Screen中重寫(xiě)navigationMovement()方法。在navigationMovement()中獲取UiApplication的對(duì)象,然后調(diào)用UiApplication.pushScreen()將另外一個(gè)界面壓入堆棧。在另外一個(gè)界面中,調(diào)用UiApplication.popScreen()將自身彈出堆棧。
***個(gè)屏幕中的代碼:
- viewplaincopytoclipboardprint?
- /*
- *滾輪滾動(dòng)事件響應(yīng)
- *滾輪動(dòng)作:向上dy=-1,向下dy=1,向左dx=-1,向右dx=1
- *@seenet.rim.device.api.ui.Screen#navigationMovement(int,int,int,int)
- */
- protectedbooleannavigationMovement(intdx,intdy,intstatus,inttime){
- //Dialog.alert("TrackBallmoved:\r\n"+"x:"+dx+"\r\ny:"+dy);
- if(dx>0&&this.isDisplayed()){
- SillyDowntheApp=(SillyDown)this.getApplication();
- theApp.popScreen(theApp.getFirstScreen());
- returntrue;
- }
- returnfalse;
- }
- /*
- *滾輪滾動(dòng)事件響應(yīng)
- *滾輪動(dòng)作:向上dy=-1,向下dy=1,向左dx=-1,向右dx=1
- *@seenet.rim.device.api.ui.Screen#navigationMovement(int,int,int,int)
- */
- protectedbooleannavigationMovement(intdx,intdy,intstatus,inttime){
- // Dialog.alert("TrackBallmoved:\r\n"+"x:"+dx+"\r\ny:"+dy);
- if(dx>0&&this.isDisplayed()){
- SillyDowntheApp=(SillyDown)this.getApplication();
- theApp.popScreen(theApp.getFirstScreen());
- returntrue;
- }
- returnfalse;
- }
- 第二個(gè)屏幕中的代碼:
- viewplaincopytoclipboardprint?
- /*
- *滾輪滾動(dòng)事件響應(yīng)
- *滾輪動(dòng)作:向上dy=-1,向下dy=1,向左dx=-1,向右dx=1
- *@seenet.rim.device.api.ui.Screen#navigationMovement(int,int,int,int)
- */
- protectedbooleannavigationMovement(intdx,intdy,intstatus,inttime){
- //TODOAuto-generatedmethodstub
- if(dx<0&&this.isDisplayed()){
- SillyDowntheApp=(SillyDown)this.getApplication();
- theApp.pushScreen(theApp.getFirstScreen());
- returntrue;
- }
- returnfalse;
- }
- /*
- *滾輪滾動(dòng)事件響應(yīng)
- *滾輪動(dòng)作:向上dy=-1,向下dy=1,向左dx=-1,向右dx=1
- *@seenet.rim.device.api.ui.Screen#navigationMovement(int,int,int,int)
- */
- protectedbooleannavigationMovement(intdx,intdy,intstatus,inttime){
- //TODOAuto-generatedmethodstub
- if(dx<0&&this.isDisplayed()){
- SillyDowntheApp=(SillyDown)this.getApplication();
- theApp.pushScreen(theApp.getFirstScreen());
- returntrue;
- }
- returnfalse;
- }
點(diǎn)評(píng):這種實(shí)現(xiàn)方式比較簡(jiǎn)單,但是效果一般。
◆實(shí)現(xiàn)二:使用Graphics封裝
思路:使用Graphics封裝一個(gè)LabelField,然后在navigationMovement()方法中重繪每個(gè)Field。
代碼:(正在編寫(xiě)中,先做個(gè)標(biāo)記)
點(diǎn)評(píng):可以使用這種方法封裝一個(gè)TabbedPane,界面顏色、寬度、高度、字體等都可以自行設(shè)置,界面比較華麗,但是代碼比較復(fù)雜。
【編輯推薦】
- BlackBerry開(kāi)發(fā)中Windows+eclipse環(huán)境配置及Helloworld
- 九步實(shí)現(xiàn)BlackBerry開(kāi)發(fā)程序發(fā)布應(yīng)用到app world
- BlackBerry開(kāi)發(fā)中七步實(shí)現(xiàn)創(chuàng)建app world賬號(hào)
- BlackBerry開(kāi)發(fā)環(huán)境中javaloader使用詳解
- 黑莓開(kāi)發(fā)中黑莓手機(jī)程序訪問(wèn)網(wǎng)絡(luò)能走代理服務(wù)器的三種方式