Methods Summary |
---|
private void | initLabelView()Construct object, initializing with any attributes we understand from a
layout file. These attributes are defined in
SDK/assets/res/any/classes.xml.
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(16);
mTextPaint.setColor(0xFF000000);
mPaddingLeft = 3;
mPaddingTop = 3;
mPaddingRight = 3;
mPaddingBottom = 3;
|
private int | measureHeight(int measureSpec)Determines the height of this view
int result;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
mAscent = (int) mTextPaint.ascent();
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text (beware: ascent is a negative number)
result = (int) (-mAscent + mTextPaint.descent()) + mPaddingTop
+ mPaddingBottom;
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
return result;
|
private int | measureWidth(int measureSpec)Determines the width of this view
int result;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text
result = (int) mTextPaint.measureText(mText) + mPaddingLeft
+ mPaddingRight;
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
return result;
|
protected void | onDraw(android.graphics.Canvas canvas)Render the text
super.onDraw(canvas);
canvas.drawText(mText, mPaddingLeft, mPaddingTop - mAscent, mTextPaint);
|
protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
setMeasuredDimension(measureWidth(widthMeasureSpec),
measureHeight(heightMeasureSpec));
|
public void | setText(java.lang.String text)Sets the text to display in this label
mText = text;
requestLayout();
invalidate();
|
public void | setTextColor(int color)Sets the text color for this label
mTextPaint.setColor(color);
invalidate();
|
public void | setTextSize(int size)Sets the text size for this label
mTextPaint.setTextSize(size);
requestLayout();
invalidate();
|