Example usage for android.widget TextView getMeasuredWidth

List of usage examples for android.widget TextView getMeasuredWidth

Introduction

In this page you can find the example usage for android.widget TextView getMeasuredWidth.

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

private void drawDebug(Canvas canvas) {
    // Draw outer numbers circle
    final float outerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS];
    canvas.drawCircle(mXCenter, mYCenter, outerRadius, mPaintDebug);

    // Draw inner numbers circle
    final float innerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS_INNER];
    canvas.drawCircle(mXCenter, mYCenter, innerRadius, mPaintDebug);

    // Draw outer background circle
    canvas.drawCircle(mXCenter, mYCenter, mCircleRadius[HOURS], mPaintDebug);

    // Draw outer rectangle for circles
    float left = mXCenter - outerRadius;
    float top = mYCenter - outerRadius;
    float right = mXCenter + outerRadius;
    float bottom = mYCenter + outerRadius;
    canvas.drawRect(left, top, right, bottom, mPaintDebug);

    // Draw outer rectangle for background
    left = mXCenter - mCircleRadius[HOURS];
    top = mYCenter - mCircleRadius[HOURS];
    right = mXCenter + mCircleRadius[HOURS];
    bottom = mYCenter + mCircleRadius[HOURS];
    canvas.drawRect(left, top, right, bottom, mPaintDebug);

    // Draw outer view rectangle
    canvas.drawRect(0, 0, getWidth(), getHeight(), mPaintDebug);

    // Draw selected time
    final String selected = String.format("%02d:%02d", getCurrentHour(), getCurrentMinute());

    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView tv = new TextView(getContext());
    tv.setLayoutParams(lp);/*from  w w  w. ja v  a 2 s  .co  m*/
    tv.setText(selected);
    tv.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    Paint paint = tv.getPaint();
    paint.setColor(DEBUG_TEXT_COLOR);

    final int width = tv.getMeasuredWidth();

    float height = paint.descent() - paint.ascent();
    float x = mXCenter - width / 2;
    float y = mYCenter + 1.5f * height;

    canvas.drawText(selected, x, y, paint);
}

From source file:com.skytree.epubtest.BookViewActivity.java

int getLabelWidth(TextView tv) {
    tv.measure(0, 0); //must call measure!      
    return tv.getMeasuredWidth(); //get height
}