当前位置: 首页>>代码示例>>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;未经允许,请勿转载。