Layout draw - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Layout draw method.

This code example shows how to use the following methods:draw, getLineCount
	private int getTextLineCount(CharSequence source, TextPaint paint, int widthPx, float textSize) {
		// Update the text paint object 
		paint.setTextSize(textSize);
 
		// Draw using a static layout 
		StaticLayout layout = new StaticLayout(source, paint, widthPx, Alignment.ALIGN_NORMAL, mSpacingMult,
				mSpacingAdd, true);
		layout.draw(TEXT_RESIZE_CANVAS);
 
		return layout.getLineCount();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:draw, getEllipsizedWidth, getHeight
mTextPaint.drawableState = getDrawableState();
 
        Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
 
        canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getEllipsizedWidth() / 2,
                (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
        switchText.draw(canvas);
 
        canvas.restore();
    } 
 
    @Override 
    public int getCompoundPaddingRight() { 
        int padding = super.getCompoundPaddingRight() + mSwitchWidth;
        if (!TextUtils.isEmpty(getText())) {
            padding += mSwitchPadding;
        } 
        return padding;
    } 
7
CodeRank
This code example shows how to use the following methods:draw, getHeight, getWidth
mTextPaint.drawableState = getDrawableState();
 
        final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
 
        canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
        switchText.draw(canvas);
 
        canvas.restore();
    } 
 
    @Override 
    public int getCompoundPaddingRight() { 
        int padding = super.getCompoundPaddingRight() + mSwitchWidth;
        if (!TextUtils.isEmpty(getText())) {
            padding += mSwitchPadding;
        } 
        return padding;
    } 
 
7
CodeRank
This code example shows how to use the following methods:draw, getHeight
	// Set the text size of the text paint object and use a static layout to render text off screen before measuring 
	private int getTextRect(CharSequence source, TextPaint paint, int width, float textSize) {
		// Update the text paint object 
		paint.setTextSize(textSize);
		// Draw using a static layout 
		StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, spacingMult, spacingAdd, false);
		layout.draw(textResizeCanvas);
		return layout.getHeight();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:draw
		initPaint(); 
	} 
 
	@Override 
	protected void onDraw(Canvas canvas) {
		Layout layout = new StaticLayout(getText(), mTextPaintOutline, getWidth(), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
		layout.draw(canvas);
		layout = new StaticLayout(getText(), mTextPaint, getWidth(), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
		layout.draw(canvas);
	} 
 
	@Override 
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		Layout layout = new StaticLayout(getText(), mTextPaintOutline, measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
		int ex = (int) (mBorderSize * 2 + 1);
		setMeasuredDimension(measureWidth(widthMeasureSpec) + ex, measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
	} 
 
	private int measureWidth(int measureSpec) {
		int result = 0;
6
CodeRank
This code example shows how to use the following methods:draw, getHeight, getWidth
        Point point = drawViewAdapter.getTextPointAt( position );
        canvas.save();
        canvas.translate( point.x, point.y );
        Layout layout = drawViewAdapter.getTextLayoutAt( position );
        doDrawUnderTextPaint( canvas, layout );
        layout.draw( canvas );
        canvas.restore();
    } 
 
    /** 
     * Draw some surface under text. This method is called just before drawing each {@link LabeledPoint}'s text. 
     *  
     * @param canvas 
     *            the canvas in which we draw. 
     * @param layout 
     *            the {@link Layout} associated to a {@link LabeledPoint}. 
     */ 
    protected void doDrawUnderTextPaint( Canvas canvas, Layout layout ) {
        if ( underTextPaint != null ) {
            int margin = DRAW_UNDER_TEXT_CORNER_RADIUS;

7
CodeRank
This code example shows how to use the following methods:draw, getHeight
This code example shows how to use the following methods:draw, getHeight, getWidth
		mTextPaint.drawableState = getDrawableState();
 
		Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
		if (switchText != null)
		{ 
			canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
			switchText.draw(canvas);
		} 
 
		canvas.restore();
	} 
 
	@Override 
	public int getCompoundPaddingRight() 
	{ 
		int padding = super.getCompoundPaddingRight() + mSwitchWidth;
		if (!TextUtils.isEmpty(getText()))
		{ 
			padding += mSwitchPadding;
		} 
6
CodeRank
This code example shows how to use the following methods:restore, rotate, save, translate, draw
   protected void onDraw(Canvas canvas){
      TextPaint textPaint = getPaint(); 
      textPaint.setColor(getCurrentTextColor());
      textPaint.drawableState = getDrawableState();
 
      canvas.save();
 
      canvas.translate(0, getHeight());
      canvas.rotate(-90);
 
//      canvas.translate(getCompoundPaddingLeft()+2, getExtendedPaddingTop()); 
      getLayout().draw(canvas);
      canvas.restore();
  } 
 
@Override 
public void onClick(View v) {
	if(mLinkedImageView != null)
		mLinkedImageView.performClick();
} 
6
CodeRank
This code example shows how to use the following methods:draw

Related Layout draw Questions & Answers:

draw Method Overview
Draw this Layout on the specified Canvas.
See Code Examples for other Android Layout Methods: