How to put text in a drawable?

后端 未结 5 1971
一生所求
一生所求 2020-11-30 01:47

I\'m trying to create a drawable on the fly to use as a background for a custom linearlayout. It needs to have hash marks and such (no big deal), but also have numbers label

5条回答
  •  甜味超标
    2020-11-30 02:18

    To answer the comments above regarding how to center the text:

    mPaint.textAlign = Align.CENTER
    ...
    // Centering for mixed case letters
    canvas.drawText(mText, 0, mText.length,
            bounds.centerX().toFloat(), bounds.centerY().toFloat() - ((mPaint.descent() + mPaint.ascent()) / 2), mPaint)
    
    // Centering for all uppercase letters
    canvas.drawText(mText, 0, mText.length,
                bounds.centerX().toFloat(), bounds.centerY().toFloat() - mPaint.ascent() / 2, mPaint)
    

提交回复
热议问题