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


Java Layout.getWidth方法代碼示例

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


在下文中一共展示了Layout.getWidth方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: adjustEllipsizeEndText

import android.text.Layout; //導入方法依賴的package包/類
private void adjustEllipsizeEndText(Layout layout) {
    try {
        final CharSequence originText = getText();
        if(TextUtils.isEmpty(originText)){
            return;
        }
        final CharSequence restSuffixText = originText.subSequence(
                originText.length() - mEllipsizeIndex, originText.length());

        final int width = layout.getWidth() - getPaddingLeft() - getPaddingRight();
        final int maxLineCount = computeMaxLineCount(layout);
        final int lastLineWidth = (int) layout.getLineWidth(maxLineCount - 1);
        final int mLastCharacterIndex = layout.getLineEnd(maxLineCount - 1);

        final int suffixWidth = (int) (Layout.getDesiredWidth(mEllipsizeText, getPaint()) +
                Layout.getDesiredWidth(restSuffixText, getPaint())) + 1;

        if (lastLineWidth + suffixWidth > width) {
            final int widthDiff = lastLineWidth + suffixWidth - width;

            final int removedCharacterCount = computeRemovedEllipsizeEndCharacterCount(widthDiff,
                    originText.subSequence(0, mLastCharacterIndex));

            setText(originText.subSequence(0, mLastCharacterIndex - removedCharacterCount));
            append(mEllipsizeText);
            append(restSuffixText);
        } else {
            setText(originText.subSequence(0, mLastCharacterIndex));
            append(mEllipsizeText);
            append(restSuffixText);
        }
    }catch (IndexOutOfBoundsException e){

    }
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:36,代碼來源:EllipsizeTextView.java

示例3: onMeasure

import android.text.Layout; //導入方法依賴的package包/類
public void onMeasure(int origWidthMeasureSpec, int origHeightMeasureSpec) {
    int widthMeasureSpec;
    int specWidthSize = MeasureSpec.getSize(origWidthMeasureSpec);
    int specWidthMode = MeasureSpec.getMode(origWidthMeasureSpec);
    int maxWidth = TabLayout.this.getTabMaxWidth();
    int heightMeasureSpec = origHeightMeasureSpec;
    if (maxWidth <= 0 || (specWidthMode != 0 && specWidthSize <= maxWidth)) {
        widthMeasureSpec = origWidthMeasureSpec;
    } else {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(TabLayout.this.mTabMaxWidth, Integer.MIN_VALUE);
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (this.mTextView != null) {
        Resources res = getResources();
        float textSize = TabLayout.this.mTabTextSize;
        int maxLines = this.mDefaultMaxLines;
        if (this.mIconView != null && this.mIconView.getVisibility() == 0) {
            maxLines = 1;
        } else if (this.mTextView != null && this.mTextView.getLineCount() > 1) {
            textSize = TabLayout.this.mTabTextMultiLineSize;
        }
        float curTextSize = this.mTextView.getTextSize();
        int curLineCount = this.mTextView.getLineCount();
        int curMaxLines = TextViewCompat.getMaxLines(this.mTextView);
        if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
            boolean updateTextView = true;
            if (TabLayout.this.mMode == 1 && textSize > curTextSize && curLineCount == 1) {
                Layout layout = this.mTextView.getLayout();
                if (layout == null || approximateLineWidth(layout, 0, textSize) > ((float) layout.getWidth())) {
                    updateTextView = false;
                }
            }
            if (updateTextView) {
                this.mTextView.setTextSize(0, textSize);
                this.mTextView.setMaxLines(maxLines);
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:41,代碼來源:TabLayout.java

示例4: setLayout

import android.text.Layout; //導入方法依賴的package包/類
/**
 * Assigns a new {@link Layout} to draw.
 */
public void setLayout(Layout layout) {
  mLayout = layout;
  mLayoutWidth = layout.getWidth();
  mLayoutHeight = LayoutMeasureUtil.getHeight(layout);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:9,代碼來源:DrawTextLayout.java


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