Code example for StaticLayout

Methods: getLineCount, getLineEnd

0
 
    private void calculateDrawingData() { 
        sDefaultPaint.setTextSize(mCoordinates.subjectFontSize);
        calculateSubjectText(); 
        mSubjectLayout = new StaticLayout(mText, sDefaultPaint,
                mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, false /* includePad */);
        if (mCoordinates.subjectLineCount < mSubjectLayout.getLineCount()) {
            // TODO: ellipsize. 
            int end = mSubjectLayout.getLineEnd(mCoordinates.subjectLineCount - 1);
            mSubjectLayout = new StaticLayout(mText.subSequence(0, end),
                    sDefaultPaint, mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, true);
        } 
 
        // Now, format the sender for its width 
        TextPaint senderPaint = mRead ? sDefaultPaint : sBoldPaint;
        // And get the ellipsized string for the calculated width 
        if (TextUtils.isEmpty(mSender)) {
            mFormattedSender = "";
        } else { 
            int senderWidth = mCoordinates.sendersWidth;
            senderPaint.setTextSize(mCoordinates.sendersFontSize);