當前位置: 首頁>>代碼示例>>Java>>正文


Java Layout類代碼示例

本文整理匯總了Java中android.text.Layout的典型用法代碼示例。如果您正苦於以下問題:Java Layout類的具體用法?Java Layout怎麽用?Java Layout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Layout類屬於android.text包,在下文中一共展示了Layout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flushView

import android.text.Layout; //導入依賴的package包/類
/**
 * Flush view no matter what height and width the {@link WXDomObject} specifies.
 * @param extra must be a {@link Layout} object, otherwise, nothing will happen.
 */
private void flushView(Object extra) {
  if (extra instanceof Layout &&
      getHostView() != null && !extra.equals(getHostView().getTextLayout())) {
    final Layout layout = (Layout) extra;
    /**The following if block change the height of the width of the textView.
     * other part of the code is the same to updateExtra
     */
    ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
    if (layoutParams != null) {
      layoutParams.height = layout.getHeight();
      layoutParams.width = layout.getWidth();
      getHostView().setLayoutParams(layoutParams);
    }
    getHostView().setTextLayout(layout);
    getHostView().invalidate();
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:22,代碼來源:WXText.java

示例2: onLayoutChange

import android.text.Layout; //導入依賴的package包/類
/**
 * Show the end of the URL rather than the beginning.
 */
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
        int oldTop, int oldRight, int oldBottom) {
    Layout layout = mUrlBar.getLayout();
    if (layout == null) return;

    // Android doesn't account for the compound Drawable in its width calculations, leading to
    // improper scrolling and even Android improperly placing the horizontal fade in its
    // TextView calculation.  Get around it by calculating that width manually: crbug.com/303908
    int urlBarWidth = mUrlBar.getWidth();
    int iconWidth =
            mCurrentIconResource == 0 ? 0 : mIconResourceWidths.get(mCurrentIconResource);
    int availableTextWidth = urlBarWidth - iconWidth;
    int desiredWidth = (int) Layout.getDesiredWidth(layout.getText(), layout.getPaint());

    if (desiredWidth > availableTextWidth) {
        mUrlBar.scrollTo(desiredWidth - availableTextWidth, 0);
    } else {
        mUrlBar.scrollTo(0, 0);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:25,代碼來源:WebappUrlBar.java

示例3: adjustBottomLines

import android.text.Layout; //導入依賴的package包/類
/**
 * @return True, if adjustments were made that require the view to be invalidated.
 */
private boolean adjustBottomLines() {
  // Bail out if we have a zero width; lines will be adjusted during next layout.
  if (getWidth() == 0) {
    return false;
  }
  int destBottomLines;
  textPaint.setTextSize(bottomTextSize);
  if (tempErrorText != null || helperText != null) {
    Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
      Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
      Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
    destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
  } else {
    destBottomLines = minBottomLines;
  }
  if (bottomLines != destBottomLines) {
    getBottomLinesAnimator(destBottomLines).start();
  }
  bottomLines = destBottomLines;
  return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:MaterialAutoCompleteTextView.java

示例4: drawLeadingMargin

import android.text.Layout; //導入依賴的package包/類
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline,
                              int bottom, CharSequence text, int start, int end, boolean first, Layout l) {
    if (first) {
        TextPaint paint = new TextPaint(p);

        paint.setStyle(Paint.Style.FILL);

        if (options.textSize != -1) {
            paint.setTextSize(options.textSize);
        }

        if (options.textColor != -1) {
            paint.setColor(options.textColor);
        }

        if (options.typeface != null) {
            paint.setTypeface(options.typeface);
        }

        c.save();
        c.drawText(data,  x + options.leadWidth, baseline, paint);
        c.restore();
    }
}
 
開發者ID:Fueled,項目名稱:snippety,代碼行數:25,代碼來源:TextIndentSpan.java

示例5: moveCursor

import android.text.Layout; //導入依賴的package包/類
private void moveCursor(int x, int y)
{
	x -= edit.getPaddingLeft();
	y -= edit.getPaddingTop();
	Layout l = edit.getLayout();
	int offset;
	int line = l.getLineForVertical(y);
	if(line == 0 && y < l.getLineTop(line))
	{
		offset = 0;
	}
	else if(line >= l.getLineCount() - 1 && y >= l.getLineTop(line + 1))
	{
		offset = l.getText().length();
	}
	else
	{
		offset = l.getOffsetForHorizontal(line, x);
	}

	edit.setSelection(offset);

}
 
開發者ID:monolifed,項目名稱:mininoteview,代碼行數:24,代碼來源:TextEdit.java

示例6: drawLeadingMargin

import android.text.Layout; //導入依賴的package包/類
@Override
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {

    if (multiline) {

        paint.setStyle(Paint.Style.FILL);
        paint.setColor(theme.getCodeBackgroundColor(p));

        final int left;
        final int right;
        if (dir > 0) {
            left = x;
            right = c.getWidth();
        } else {
            left = x - c.getWidth();
            right = x;
        }

        rect.set(left, top, right, bottom);

        c.drawRect(rect, paint);
    }
}
 
開發者ID:noties,項目名稱:Markwon,代碼行數:24,代碼來源:CodeSpan.java

示例7: configureTextLayouts

import android.text.Layout; //導入依賴的package包/類
private void configureTextLayouts(final int availableWidth) {
    if (!textLayoutsConfigured) {
        final int totalNeededPadding = getPaddingLeft() + getPaddingRight();

        // Create new static layout only if needed!
        if ((titleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.titleLayout = new StaticLayout(title,
                    titlePaint,
                    availableWidth,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        // Create new static layout only if needed!
        if ((subtitleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.subtitleLayout = new StaticLayout(subtitle,
                    subtitlePaint,
                    availableWidth,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        textLayoutsConfigured = true;
    }
}
 
開發者ID:tylersuehr7,項目名稱:empty-state-recyclerview,代碼行數:26,代碼來源:TextStateDisplay.java

示例8: drawIndicatorsTextAbove

import android.text.Layout; //導入依賴的package包/類
private void drawIndicatorsTextAbove(Canvas canvas, String text, TextPaint paintText, float x, float y, Layout.Alignment alignment) {

        final float textHeight = calculateTextMultilineHeight(text, paintText);
        y -= textHeight;

        final int width = (int) paintText.measureText(text);
        if (x >= getWidth() - settings.paddingCorners) {
            x = (getWidth() - width - settings.paddingCorners / 2f);
        } else if (x <= 0) {
            x = width / 2f;
        } else {
            x = (x - width / 2f);
        }

        if (x < 0) {
            x = 0;
        }

        if (x + width > getWidth()) {
            x = getWidth() - width;
        }

        drawText(canvas, text, x, y, paintText, alignment);
    }
 
開發者ID:florent37,項目名稱:android-slidr,代碼行數:25,代碼來源:Slidr.java

示例9: getPreciseOffset

import android.text.Layout; //導入依賴的package包/類
public static int getPreciseOffset(TextView textView, int x, int y) {
    Layout layout = textView.getLayout();
    if (layout != null) {
        int topVisibleLine = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(topVisibleLine, x);

        int offsetX = (int) layout.getPrimaryHorizontal(offset);

        if (offsetX > x) {
            return layout.getOffsetToLeftOf(offset);
        } else {
            return offset;
        }
    } else {
        return -1;
    }
}
 
開發者ID:shenhuanet,項目名稱:SelectableTextProvider,代碼行數:18,代碼來源:TextLayoutUtil.java

示例10: getTextDirection

import android.text.Layout; //導入依賴的package包/類
private static String getTextDirection(Spanned text, int start, int end) {
        // FIXME not supported
        int paraDir = Layout.DIR_LEFT_TO_RIGHT;
//        final int len = end - start;
//        final byte[] levels = ArrayUtils.newUnpaddedByteArray(len);
//        final char[] buffer = TextUtils.obtain(len);
//        TextUtils.getChars(text, start, end, buffer, 0);
//        int paraDir = AndroidBidi.bidi(Layout.DIR_REQUEST_DEFAULT_LTR, buffer, levels, len,
//                false /* no info */);
        switch (paraDir) {
            case Layout.DIR_RIGHT_TO_LEFT:
                return " dir=\"rtl\"";
            case Layout.DIR_LEFT_TO_RIGHT:
            default:
                return " dir=\"ltr\"";
        }
    }
 
開發者ID:Pixplicity,項目名稱:HtmlCompat,代碼行數:18,代碼來源:HtmlCompat.java

示例11: getTextHeightPixels

import android.text.Layout; //導入依賴的package包/類
/**
 * Sets the text size of a clone of the view's {@link TextPaint} object
 * and uses a {@link StaticLayout} instance to measure the height of the text.
 *
 * @param source
 * @param availableWidthPixels
 * @param textSizePixels
 * @return the height of the text when placed in a view
 * with the specified width
 * and when the text has the specified size.
 */
private int getTextHeightPixels(
        CharSequence source,
        int availableWidthPixels,
        float textSizePixels) {
    // Make a copy of the original TextPaint object
    // since the object gets modified while measuring
    // (see also the docs for TextView.getPaint()
    // which states to access it read-only)
    TextPaint textPaintCopy = new TextPaint(getPaint());
    textPaintCopy.setTextSize(textSizePixels);
    // Measure using a StaticLayout instance
    StaticLayout staticLayout = new StaticLayout(
            source,
            textPaintCopy,
            availableWidthPixels,
            Layout.Alignment.ALIGN_NORMAL,
            mLineSpacingMultiplier,
            mLineSpacingExtra,
            true);
    return staticLayout.getHeight();
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:33,代碼來源:AutoResizeTextView.java

示例12: isTitleTruncated

import android.text.Layout; //導入依賴的package包/類
public boolean isTitleTruncated() {
    if (this.mTitleTextView == null) {
        return false;
    }
    Layout titleLayout = this.mTitleTextView.getLayout();
    if (titleLayout == null) {
        return false;
    }
    int lineCount = titleLayout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
        if (titleLayout.getEllipsisCount(i) > 0) {
            return true;
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:Toolbar.java

示例13: drawLeadingMargin

import android.text.Layout; //導入依賴的package包/類
public void drawLeadingMargin(Canvas c,
                              Paint p,
                              int x,
                              int dir,
                              int top,
                              int baseline,
                              int bottom,
                              CharSequence text,
                              int start,
                              int end,
                              boolean first,
                              Layout layout) {
    Paint.Style prevStyle = p.getStyle();
    int prevColor = p.getColor();
    p.setStyle(Paint.Style.FILL);
    p.setColor(lineColor);
    c.drawRect(x, top, x + dir * lineWidth, bottom, p);
    p.setStyle(prevStyle);
    p.setColor(prevColor);
}
 
開發者ID:PaulKlinger,項目名稱:Sprog-App,代碼行數:21,代碼來源:FancyQuoteSpan.java

示例14: textTouchEvent

import android.text.Layout; //導入依賴的package包/類
/**
 * 微博文本觸摸監聽處理
 *
 * @param textView 點擊的TextView
 * @param event
 * @return true:點擊事件被處理;false:點擊事件未被處理,向上冒泡
 */
private boolean textTouchEvent(TextView textView, MotionEvent event) {
    boolean ret = false;
    CharSequence text = textView.getText();
    Spannable sText = Spannable.Factory.getInstance().newSpannable(text);
    int action = event.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= textView.getTotalPaddingLeft();
        y -= textView.getTotalPaddingTop();
        x += textView.getScrollX();
        y += textView.getScrollY();
        Layout layout = textView.getLayout();
        int line = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(line, x);
        ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class);
        if (links.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                links[0].onClick(textView);
            }
            ret = true;
        }
    }
    return ret;
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:33,代碼來源:StatusDataSetter.java

示例15: updateSecretTimeText

import android.text.Layout; //導入依賴的package包/類
private void updateSecretTimeText() {
    if (currentMessageObject == null) {
        return;
    }
    String str = currentMessageObject.getSecretTimeString();
    if (str == null) {
        return;
    }
    if (currentInfoString == null || !currentInfoString.equals(str)) {
        currentInfoString = str;
        infoWidth = (int)Math.ceil(infoPaint.measureText(currentInfoString));
        CharSequence str2 = TextUtils.ellipsize(currentInfoString, infoPaint, infoWidth, TextUtils.TruncateAt.END);
        infoLayout = new StaticLayout(str2, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        invalidate();
    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:17,代碼來源:SecretPhotoViewer.java


注:本文中的android.text.Layout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。