Android Layout - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:setColor, setShadowLayer, setTextSize, setTypeface, getDesiredWidth
		if (valuePaint == null) {
			if (typefaceWeight == Typeface.BOLD) {
				valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG
						| Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
			} else { 
				valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG
						| Paint.DITHER_FLAG);
			} 
			//valuePaint.density = getResources().getDisplayMetrics().density; 
			valuePaint.setTextSize(textSize);
			valuePaint.setShadowLayer(0.5f, 0, 0.5f, 0xFFFFFFFF);
			valuePaint.setTypeface(typeface);
			valuePaint.setColor((textColor == NOVAL) ? ITEMS_TEXT_COLOR : textColor);
		} 
 
		if (centerDrawable == null) {
			centerDrawable = getWheelValDrawable(); //getContext().getResources().getDrawable(R.drawable.wheel_val);
		} 
 
		if (topShadow == null) {

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAlpha, setAntiAlias, setTextSize, setTypeface, getDesiredWidth
    ++n;
    return (n <= 0) ? 1 : n;
  } 
 
  private void prepareLayout() { 
    float desiredWidth = Layout.getDesiredWidth(text, paint);
 
    textWidth = (int)Math.ceil(desiredWidth);
    if (textWidth > maxWidthPixels) {
      textWidth = maxWidthPixels;
    } 
    else if (textWidth <= 0) {
      textWidth = 1;
    } 
 
    Layout.Alignment _alignment = Layout.Alignment.ALIGN_NORMAL;
 
    if (alignment == 1) {
      _alignment = Layout.Alignment.ALIGN_CENTER;
    } 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getLineForVertical, getOffsetForHorizontal
 
			x += widget.getScrollX();
			y += widget.getScrollY();
 
			Layout layout = widget.getLayout();
			int line = layout.getLineForVertical(y);
			int off = layout.getOffsetForHorizontal(line, x);
 
			ClickableSpan[] links = buffer.getSpans(off, off,
					ClickableSpan.class);
 
			if (links.length != 0 && links[0] instanceof URLSpan) {
				HashMap args = new HashMap();
				args.put("url", ((URLSpan) links[0]).getURL());
				_proxy.fireEvent("click", args);
				return true; 
			} 
		} 
		return super.onTouchEvent(widget, buffer, event);
	} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, getWidth
                mOnLayout = makeLayout(mTextOn);
            } 
            if (mOffLayout == null) {
                mOffLayout = makeLayout(mTextOff);
            } 
            final int minWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth())
                    + getPaddingLeft() + getPaddingRight();
            final int minHeight = Math.max(mOnLayout.getHeight(), mOffLayout.getHeight())
                    + getPaddingLeft() + getPaddingRight();
            setMeasuredDimension(resolveSizeAndState(minWidth, widthMeasureSpec, 0),
                    resolveSizeAndState(minHeight, heightMeasureSpec, 0));
        } 
 
        private Layout makeLayout(CharSequence text) {
            return new StaticLayout(text, mTextPaint,
                    (int) Math.ceil(Layout.getDesiredWidth(text, mTextPaint)),
                    Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true);
        } 
 
        @Override 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getLineForVertical, getOffsetForHorizontal
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getLineEnd, getLineCount
 
    private void calculateDrawingData() { 
        sDefaultPaint.setTextSize(mCoordinates.subjectFontSize);
        calculateSubjectText(); 
        mSubjectLayout = new StaticLayout(mText, sDefaultPaint,
                mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, false /* includePad */);
        if (mCoordinates.subjectLineCount < mSubjectLayout.getLineCount()) {
            // TODO: ellipsize. 
            int end = mSubjectLayout.getLineEnd(mCoordinates.subjectLineCount - 1);
            mSubjectLayout = new StaticLayout(mText.subSequence(0, end),
                    sDefaultPaint, mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, true);
        } 
 
        // Now, format the sender for its width 
        TextPaint senderPaint = mRead ? sDefaultPaint : sBoldPaint;
        // And get the ellipsized string for the calculated width 
        if (TextUtils.isEmpty(mSender)) {
            mFormattedSender = "";
        } else { 
            int senderWidth = mCoordinates.sendersWidth;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight
 
        // Layout the text. 
        int outerWidth = right - config.mTitleLeft;
        String title = mTitle;
        mTitleLayout = new StaticLayout(title, 0, title.length(), config.mPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0,
                true, TextUtils.TruncateAt.MIDDLE, outerWidth);
        mTitleY = top + (height - mTitleLayout.getHeight()) / 2;
    } 
 
    public static final class Config { 
        private final int mIconLeft;
        private final int mTitleLeft;
        private final int mIconSize;
        private final TextPaint mPaint;
 
        public Config(int iconSpan, int iconSize, TextPaint paint) {
            mIconLeft = (iconSpan - iconSize) / 2;
            mTitleLeft = iconSpan;
            mIconSize = iconSize;
            mPaint = paint;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Layout Questions & Answers:

See Code Examples for Android Layout Methods: