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