zoukankan      html  css  js  c++  java
  • (转)Android 、BlackBerry 文本对齐方式对比

    http://tech.cncms.com/shouji/android/77024_2.html

    Android和BlackBerry文本对齐方式的写法不一样。

    首先Android文本对齐有相对的概念,也就是说当使用文本对齐,你还需要设定相对哪个坐标点才能进行,否则的话就不能达到想要的效果,而BlackBerry则不需要,只要设置对齐方式,就会相对于所画区域的大小自动对齐。

    Android是使用Paint和Canvas共同控制绘图,而BlackBerry只要Graphics就可以了。

    请看Android的代码:

    Java代码

    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);

    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的位置,这都是相对的概念,Android BlackBerry 文本对齐方式对比(2),下面是BlackBerry的代码:Java代码

    Bitmap bitmap = new Bitmap(imageWidth, imageHeight);

    Graphics graphics = Graphics.create(bitmap);

    graphics.drawText("This is the demo", 0, 0, Graphics.HCENTER,

    Display.getWidth());

    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的对齐方式还能进行组合使用,比如:

    Java代码

    graphics.drawText("This is the demo", 0, 0,  Graphics.HCENTER|Graphics.VFULL,

    Display.getWidth());

    graphics.drawText("This is the demo", 0, 0,  Graphics.HCENTER|Graphics.VFULL,

    Display.getWidth());

    所以Android和BB在文本对齐的方式上有很大的不同。




     

    Bitmap bitmap = new Bitmap(imageWidth, imageHeight);

    Graphics graphics = Graphics.create(bitmap);

    graphics.drawText("This is the demo", 0, 0, Graphics.HCENTER,

    Display.getWidth());

    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的对齐方式还能进行组合使用,比如:

    Java代码

    graphics.drawText("This is the demo", 0, 0,  Graphics.HCENTER|Graphics.VFULL,

    Display.getWidth());

    graphics.drawText("This is the demo", 0, 0,  Graphics.HCENTER|Graphics.VFULL,

    Display.getWidth());

    所以Android和BB在文本对齐的方式上有很大的不同。

    -

  • 相关阅读:
    互动留言赠书:《Oracle高性能系统实战大全》
    超融合硬件损坏导致Oracle RAC异常恢复实录
    架构师不得不了解的硬件知识
    加班做的可视化被老板嫌弃,是因为你不会用这些数据工具
    iOS开发之七:常用控件--UISlider、UISegmentedControl、UIPageControl的使用
    iOS开发之六:常用控件--UIImageView的使用
    iOS开发之五:常用控件--UITextField的使用
    Objective-C实现常用的4种排序算法
    C语言实现4种常用排序
    面试常用的4种数组排序
  • 原文地址:https://www.cnblogs.com/Jessy/p/2363526.html
Copyright © 2011-2022 走看看