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在文本对齐的方式上有很大的不同。

    -

  • 相关阅读:
    AGC015E Mr.Aoki Incubator
    luogu P3520 [POI2011]SMI-Garbage
    442.Find All Duplicates in an Array
    SICP_2.61-2.62
    sicp_2.59-2.60
    SICP_2.58
    SICP_2.56-2.57
    SICP_2.53-2.55
    SICP_2.52-2.53
    SICP_2.50-2.51
  • 原文地址:https://www.cnblogs.com/Jessy/p/2363526.html
Copyright © 2011-2022 走看看