本文整理汇总了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();
}
}
示例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){
}
}
示例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);
}
}
}
}
示例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);
}