android bitmap繪制文字自動換行


public Bitmap getNewBitMap(String text) {
        Bitmap newBitmap = Bitmap.createBitmap(120,150, Config.ARGB_4444);
        Canvas canvas = new Canvas(newBitmap);
        canvas.drawBitmap(bmp, 0, 0, null);
        TextPaint textPaint = new TextPaint();
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(16.0F);
        StaticLayout sl= new StaticLayout(text, textPaint, newBitmap.getWidth()-8, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
        canvas.translate(6, 40);
        sl.draw(canvas);
        return newBitmap;
    }

 

android StaticLayout參數解釋

StaticLayout layout = new StaticLayout(context.getString(R.string.about),textPaint,(int)(300*fDensity),Alignment.ALIGN_CENTER,1.5F,0,false);
layout.draw(canvas);
參數含義:
1.字符串子資源
2 .畫筆對象
3.layout的寬度,字符串超出寬度時自動換行。
4.layout的樣式,有ALIGN_CENTER, ALIGN_NORMAL, ALIGN_OPPOSITE 三種。
5.相對行間距,相對字體大小,1.5f表示行間距為1.5倍的字體高度。
6.相對行間距,0表示0個像素。
實際行間距等於這兩者的和。
7.還不知道是什么意思,參數名是boolean includepad。
需要指出的是這個layout是默認畫在Canvas的(0,0)點的,如果需要調整位置只能在draw之前移Canvas的起始坐標
canvas.translate(x,y);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM