當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。