Code example for TextPaint

Methods: descent, ellipsize

0
 
        // If user is dragging the scroll bar, draw the alphabet overlay 
        if (mState == STATE_DRAGGING && mDrawOverlay) {
            mOverlayDrawable.draw(canvas);
            final TextPaint paint = mPaint;
            float descent = paint.descent();
            final RectF rectF = mOverlayPos;
            final String text = TextUtils.ellipsize(mSectionText, paint, (mOverlayPos.right - mOverlayPos.left) * 0.8f, TextUtils.TruncateAt.END).toString();
            canvas.drawText(text, (int) (rectF.left + rectF.right) / 2,
            // Base of text at: (middle) + (half text height) - descent : so it is vertically centred 
                    (int) (rectF.bottom + rectF.top) / 2 + mOverlaySize / 6 - descent, paint);
        } else if (mState == STATE_EXIT) {
            if (alpha == 0) { // Done with exit
                setState(STATE_NONE);
            } else { 
                mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
            } 
        } 
    } 
 
    void onSizeChanged(int w, int h, int oldw, int oldh) {