本文整理汇总了Java中android.text.Layout.getLineWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.getLineWidth方法的具体用法?Java Layout.getLineWidth怎么用?Java Layout.getLineWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Layout
的用法示例。
在下文中一共展示了Layout.getLineWidth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClickableSpanUnderTouch
import android.text.Layout; //导入方法依赖的package包/类
private BetterLinkMovementExtended.ClickableSpanWithText findClickableSpanUnderTouch(TextView textView, Spannable text, MotionEvent event) {
int touchX = (int) event.getX();
int touchY = (int) event.getY();
touchX -= textView.getTotalPaddingLeft();
touchY -= textView.getTotalPaddingTop();
touchX += textView.getScrollX();
touchY += textView.getScrollY();
Layout layout = textView.getLayout();
int touchedLine = layout.getLineForVertical(touchY);
int touchOffset = layout.getOffsetForHorizontal(touchedLine, (float) touchX);
this.touchedLineBounds.left = layout.getLineLeft(touchedLine);
this.touchedLineBounds.top = (float) layout.getLineTop(touchedLine);
this.touchedLineBounds.right = layout.getLineWidth(touchedLine) + this.touchedLineBounds.left;
this.touchedLineBounds.bottom = (float) layout.getLineBottom(touchedLine);
if (this.touchedLineBounds.contains((float) touchX, (float) touchY)) {
Object[] spans = text.getSpans(touchOffset, touchOffset, SPAN_CLASS);
for (Object span : spans) {
if (span instanceof ClickableSpan) {
return ClickableSpanWithText.ofSpan(textView, (ClickableSpan) span);
}
}
return null;
} else {
return null;
}
}
示例2: getMaxLineWidth
import android.text.Layout; //导入方法依赖的package包/类
private float getMaxLineWidth(Layout layout) {
float max_width = 0.0f;
int lines = layout.getLineCount();
for (int i = 0; i < lines; i++) {
if (layout.getLineWidth(i) > max_width) {
max_width = layout.getLineWidth(i);
}
}
return max_width;
}
示例3: 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){
}
}
示例4: handleTouchEvent
import android.text.Layout; //导入方法依赖的package包/类
public boolean handleTouchEvent(MotionEvent event) {
int action = event.getAction();
if (action != MotionEvent.ACTION_UP
&& action != MotionEvent.ACTION_DOWN) {
return true;
} else {
int x = (int) event.getX();
int y = (int) event.getY();
x -= getTotalPaddingLeft();
y -= getTotalPaddingTop();
x += getScrollX();
y += getScrollY();
Layout layout = getLayout();
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
float width = layout.getLineWidth(line);
if (y > width) {
offset = y;
}
if (!(getText() instanceof Spannable)) {
return true;
} else {
Spannable span = (Spannable) getText();
ClickableSpan[] clickSpan = span.getSpans(offset, offset,
ClickableSpan.class);
if (clickSpan == null || clickSpan.length == 0) {
am[] aam = span.getSpans(offset, offset, am.class);
if (aam != null && aam.length != 0)
return false;
return true;
} else {
return false;
}
}
}
}
示例5: approximateLineWidth
import android.text.Layout; //导入方法依赖的package包/类
/**
* Approximates a given lines width with the new provided text size.
*/
private float approximateLineWidth(Layout layout, int line, float textSize) {
return layout.getLineWidth(line) * (textSize / layout.getPaint().getTextSize());
}
示例6: onDraw
import android.text.Layout; //导入方法依赖的package包/类
@SuppressLint("DrawAllocation")
@Override
public void onDraw(@NonNull Canvas canvas) {
Layout layout = getLayout();
if (layout != null) {
int count = getLineCount();
int scrollY = getScrollY();
mFirst = layout.getLineForVertical(scrollY);
mLast = layout.getLineForVertical(getHeight() + scrollY);
getDrawingRect(mDrawingRect);
mScrollMax.x = 0;
getLineBounds(count - 1, mLineBounds);
mScrollMax.y = Math.max((mLineBounds.bottom + mPadding) - mDrawingRect.height(), 0);
int usableWidth = mDrawingRect.width() - (mLeftPadding + mPadding);
if(HIGHLIGHT_CURRENT_LINE) {
getLineBounds(getLine(), mLineBounds);
canvas.drawRect(mLineBounds, mPaintHighlight);
}
if (SHOW_LINE_NUMBERS) {
updateLinePadding();
int lineX = (int) (mDrawingRect.left + mLeftPadding - (FIXED_TEXT_SIZE * 0.5));
canvas.drawLine(lineX, mDrawingRect.top, lineX, mDrawingRect.bottom, mPaintNumbers);
}
int i = mFirst;
while (i <= mLast) {
int baseline = getLineBounds(i, mLineBounds);
if(SHOW_LINE_NUMBERS) {
canvas.drawText("" + (i + 1), mDrawingRect.left, baseline, mPaintNumbers);
}
int lineWidth = (int) layout.getLineWidth(i);
if (lineWidth > usableWidth) {
mScrollMax.x = Math.max(mScrollMax.x, (lineWidth - usableWidth) + mPadding);
}
i++;
}
if (!(mSizeRedrawInvoked || mOnSizeRedrawListener == null)) {
mSizeRedrawInvoked = true;
mOnSizeRedrawListener.onSizeRedraw();
}
}
super.onDraw(canvas);
}
示例7: approximateLineWidth
import android.text.Layout; //导入方法依赖的package包/类
private float approximateLineWidth(Layout layout, int line, float textSize) {
return layout.getLineWidth(line) * (textSize / layout.getPaint().getTextSize());
}