Android 、BlackBerry 文本对齐方式对比
16lz
2021-01-23
版权所有,欢迎转载,转载请注明 : SinFrancis http://mdev.cc
Android和BlackBerry文本对齐方式的写法不一样。
首先Android文本对齐有相对的概念,也就是说当使用文本对齐,你还需要设定相对哪个坐标点才能进行,否则的话就不能达到想要的效果,而BlackBerry则不需要,只要设置对齐方式,就会相对于所画区域的大小自动对齐。
Android是使用Paint和Canvas共同控制绘图,而BlackBerry只要Graphics就可以了。
请看Android的代码:
int imageWidth=200;int imageHeight=200;Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);Paint p = new Paint();p.reset();p.setColor(Color.GRAY);p.setTextSize(24);p.setAntiAlias(true);//消除锯齿p.setTextAlign(Align.CENTER);//居中对齐//canvas.drawRect(0, 0, imageWidth, imageHeight, p);p.setColor(Color.BLACK);canvas.drawText("this is the demo", imageWidth>>1, 20, p);p.setTextAlign(Align.RIGHT);//右对齐canvas.drawText("this is demo", imageWidth, 49, p);
请注意canvas.drawText("this is the demo", imageWidth>>1, 20, p);
这句话的 x的坐标值为 : imageWidth>>1 ,也就是说整个图的中间位置,那么居中对齐的坐标点中心点在此位置
canvas.drawText("this is demo", imageWidth, 49, p);
这句话则说明居右对齐的点在imageWidth的位置,这都是相对的概念。
下面是BlackBerry的代码:
Bitmap bitmap = new Bitmap(imageWidth, imageHeight);Graphics graphics = Graphics.create(bitmap);graphics.drawText("This is the demo", 0, 0, Graphics.HCENTER,Display.getWidth());
graphics.drawText("This is the demo", 0, 0, Graphics.HCENTER,
Display.getWidth());
这段代码是说让文本居中对齐 Graphics.HCENTER,那么Display.getWidth()就是所画的区域宽度。
另外BlackBerry的对齐方式还能进行组合使用,比如:
graphics.drawText("This is the demo", 0, 0, Graphics.HCENTER|Graphics.VFULL,Display.getWidth());
所以Android和BB在文本对齐的方式上有很大的不同。
更多相关文章
- Android Google Map实例 - 添加GPS位置标注(Android mapview)
- Android:DropPopMenu — 显示位置跟随操作按钮显示的带箭头的弹出
- Android 以widget的方式集成Dcloud h5+SDK
- (转)Android中LocationManager的简单使用,获取当前位置
- Android 创建与解析XML(二)—— Dom方式(源码)
- Android创建逐帧动画的方式
- 根据文本生成位图
- Android中的常见FC及解决方式整理