做黑莓UI开发一般都会遇到九宫格问题,现将我最近写的一小段例子分享一下。

MainUIScreen :负责九宫格布局的

/*** */
package com.blackberry.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.FlowFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import com.blackberry.ui.component.BitmapLabelField;
import com.blackberry.ui.container.ForegroundManager;
/*** @author zhqguo* @date 2011-4-29* @version 1.0* */
public class MainUIScreen extends MainScreen {private ForegroundManager _foreground;private FlowFieldManager _manager;public MainUIScreen() {super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT | USE_ALL_WIDTH);setTitle("黑莓九宫格设计");_foreground = new ForegroundManager();_manager = new FlowFieldManager();BitmapLabelField bf1 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));bf1.setChangeListener(new FieldChangeListener() {public void fieldChanged(Field field, int context) {Dialog.alert("Hello");}});BitmapLabelField bf2 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));bf2.setChangeListener(new FieldChangeListener() {public void fieldChanged(Field field, int context) {Dialog.alert("Hello");}});BitmapLabelField bf3 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf4 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf5 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf6 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf7 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf8 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));BitmapLabelField bf9 = new BitmapLabelField("测试模块", Bitmap.getBitmapResource("png-0015.png"));setMargin(bf1);setMargin(bf2);setMargin(bf3);setMargin(bf4);setMargin(bf5);setMargin(bf6);setMargin(bf7);setMargin(bf8);setMargin(bf9);_manager.add(bf1);_manager.add(bf2);_manager.add(bf3);_manager.add(bf4);_manager.add(bf5);_manager.add(bf6);_manager.add(bf7);_manager.add(bf8);_manager.add(bf9);_foreground.add(_manager);add(_foreground);}/*** 设置图标显示位置* * @param bf*/private void setMargin(BitmapLabelField bf) {bf.setMargin(10, 60, 10, 60);}
}

BitmapLabelField :设置图标和文字显示样式

package com.blackberry.ui.component;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
/*** * @author zhqguo* @date 2011-4-28* @version 1.0* */
public class BitmapLabelField extends Field {private String _title;private Bitmap _bitmap;public BitmapLabelField(String title, Bitmap bitmap) {this(title, bitmap, 0);}public BitmapLabelField(String title, Bitmap bitmap, long style) {super(Field.FOCUSABLE | style);_title = title;_bitmap = bitmap;}/*** 设置显示区域大小*/protected void layout(int width, int height) {setExtent(80, 90);}/*** 设置图标显示位置*/protected void paint(Graphics g) {g.drawBitmap(8, 0, _bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0,0);g.setFont(g.getFont().derive(Font.BOLD, 21));g.drawText(_title, 0, _bitmap.getHeight() + 4, g.HCENTER);}/*** 设置域选中时的样式*/protected void drawFocus(Graphics g, boolean on) {g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);paintBackground(g);paint(g);}/*** 设置域的背景*/protected void paintBackground(Graphics g) {if (!isFocus()) {super.paintBackground(g);return;}int oldColour = g.getColor();try {XYRect rt = getExtent();XYRect rect = new XYRect(0, 0, rt.width, rt.height);SfBackgroundFactory.createLinearGradientRoundBackground(Color.BLUE,Color.BLUE, Color.LIGHTSKYBLUE, Color.LIGHTSKYBLUE, 20, 20).draw(g, rect);} finally {g.setColor(oldColour);}}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) {clickButton();return true;}protected boolean trackwheelClick(int status, int time) {clickButton();return true;}protected boolean invokeAction(int action) {switch (action) {case ACTION_INVOKE: {clickButton();return true;}}return super.invokeAction(action);}public void setDirty(boolean dirty) {// We never want to be dirty or muddy}public void setMuddy(boolean muddy) {// We never want to be dirty or muddy}/*** A public way to click this button*/public void clickButton() {fieldChangeNotify(0);}
}

黑莓开发之经典九宫格设计相关推荐

  1. 10款 Mac 经典原型设计开发软件推荐

    在Mac上有大量强大的开发和设计工具,今天和大家推荐10款Mac上的经典原型设计开发工具,原型设计工具是开发者必备的一款工具,无论是网站开发还是移动APP开发,都需要在前期进行严格细致的原型设计,才能 ...

  2. HTML5移动应用开发入门经典 中文pdf扫描版

    HTML5是关注度ZUI高的前沿Web技术,而移动互联网则是近两年ZUI炙手可热的Web领域.<HTML5移动应用开发入门经典>将这两者巧妙结合起来,详细讲解了如何利用HTML5进行移动应 ...

  3. 《HTML5移动应用开发入门经典》—— 1.1 了解HTML5的由来

    本节书摘来异步社区<HTML5移动应用开发入门经典>一书中的第1章,第1.1节,作者:[美]Jennifer Kyrnin,更多章节内容可以访问云栖社区"异步社区"公众 ...

  4. 经典网页设计:10个响应式设计的国外购物网站

    今天我想与大家分享电子商务主题的网站设计,更精确地说是为设计在线商店提供新思想.每个人都知道移动技术的市场发展迅速,已经很难找到一个人没有手机的人了.响应设计给我们提供了一个巨大的机遇:站点的访问量的 ...

  5. 经典网页设计:20例与众不同的网页联系表单设计

    网站是企业宣传和展示其产品的一个非常好的媒介,同时也是收集用户建议和评价的最佳途径.作为网站最重要的组成部分之一,联系表单是用户反馈信息的重要窗口.联系表单的设计应该具有创意性,能够吸引用户的注意力, ...

  6. 经典网页设计:18个示例展示图片在网页中的使用

    我们可以说,最近图像占据了网页设计的中心舞台.因此,我们已经看到了一些真正美丽的网站使用了圆滑图像作为焦点,引人注目.在网页设计中,从简约设计的概念到全屏的背景图片,有几种不同的图像使用方法.所以今天 ...

  7. iOS开发UI篇—九宫格坐标计算

    iOS开发UI篇-九宫格坐标计算 一.要求 完成下面的布局 二.分析 寻找左边的规律,每一个uiview的x坐标和y坐标. 三.实现思路 (1)明确每一块用得是什么view (2)明确每个view之间 ...

  8. 《HTML5移动应用开发入门经典》—— 1.6 编写移动网站

    本节书摘来异步社区<HTML5移动应用开发入门经典>一书中的第1章,第1.6节,作者:[美]Jennifer Kyrnin,更多章节内容可以访问云栖社区"异步社区"公众 ...

  9. IT开发工程师经典面试

    IT开发工程师经典面试 1.请你自我介绍一下你自己? 回答提示:一般人回答这个问题过于平常,只说姓名.年龄.爱好.工作经验,这些在简历上都有.其实,企业最希望知道的是求职者能否胜任工作,包括:最强的技 ...

  10. Android开发的经典入门教材和学习…

    Android开发的经典入门教材和学习路线? 1.想利用寒假期间学习Android开发,了解到应该先学习Java,不知道选哪本书入门,学习Java和Android有什么经典教材,适合初学者.(有C++ ...

最新文章

  1. 【STM32 .Net MF开发板学习-17】Wifi遥控智能小车
  2. HighNewTech之QAB:重新温读张首晟教授2018年8月演讲PPT《量子计算, 人工智能与区块链》
  3. 卡片游戏 数学期望
  4. C++全局变量和局部变量有什么区别
  5. class声明为final的好处
  6. Mac文件共享不起作用时该怎么办
  7. 帝国cms清除html标签,帝国CMS如何删除清空旧数据让栏目文章ID从1开始起(一)...
  8. 如何挖掘评论中的关键信息
  9. Python 的 MySQL 模块
  10. php 图片填充图片,php imagefilledrectangle在图片画一矩形并填充
  11. 斐讯K2路由器刷固件实现校园网可使用
  12. MT4本地跟单使用说明
  13. 谷歌 draco学习 二 压缩点信息
  14. HTML中给Button加图片背景的具体写法
  15. 【色彩管理】色彩管理之灰平衡
  16. 【答粉丝问】前公司挽留涨薪,已经接到下一家公司的offer,是走还是留?
  17. 大咖访谈丨金星分享2020年直播数据,助农产品如何走上产销快车道
  18. 机器学习识别颜色_使用机器学习为颜色命名
  19. 如何查看电脑上是否安装了MySQL
  20. Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/sear

热门文章

  1. 大数据hadoop,spark,flink等经典电子书PDF下载
  2. 360搭建windows补丁服务器
  3. 万达酒店及度假村旗下“万达颐华”品牌第一家直营酒店正式开业
  4. Flutter封装加载状态视图,加载中、加载成功、加载失败、加载无数据
  5. 纯JavaScript实现鼠标拖尾效果
  6. Eprime Feedback state激活错误 其他报错
  7. 百度SEO标题关键词伪原创组合工具
  8. 怎样在电脑上面简单的记账,了解账户收支
  9. 概率论——分布函数的性质
  10. 手机图形计算器matlab,科学图形计算器 Mathlab