当前位置: 首页>>代码示例>>Java>>正文


Java Layout.getLineWidth方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:27,代码来源:BetterLinkMovementExtended.java

示例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;
}
 
开发者ID:dimorinny,项目名称:show-case-card-view,代码行数:11,代码来源:WrapWidthTextView.java

示例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){

    }
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:36,代码来源:EllipsizeTextView.java

示例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;
            }
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:41,代码来源:TweetTextView.java

示例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());
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:7,代码来源:TabLayoutLite.java

示例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);
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:43,代码来源:LModEditor.java

示例7: approximateLineWidth

import android.text.Layout; //导入方法依赖的package包/类
private float approximateLineWidth(Layout layout, int line, float textSize) {
    return layout.getLineWidth(line) * (textSize / layout.getPaint().getTextSize());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:TabLayout.java


注:本文中的android.text.Layout.getLineWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。