0

テキストビューの高さに基づいてテキストのサイズを変更するコードを最終的に見つけました。Sourceですが、この関数でテキストを渡す方法がわかりません。私のテキストは別のインテントから取得されています

public int getHeightOfMultiLineText(String text,int textSize, int maxWidth) {
        TextPaint paint = new TextPaint();
        paint.setTextSize(textSize);
        int index = 0;
        int linecount = 0;
        while(index < text.length()) {
            index += paint.breakText(text,index,text.length(),true,maxWidth,null);
            linecount++;
        }

        Rect bounds = new Rect();
        paint.getTextBounds("Yy", 0, 2, bounds);
        // obtain space between lines
        double lineSpacing = Math.max(0,((linecount - 1) * bounds.height()*0.25)); 

        return (int)Math.floor(lineSpacing + linecount * bounds.height());

    }
4

1 に答える 1