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


Java Layout.getLineTop方法代码示例

本文整理汇总了Java中android.text.Layout.getLineTop方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.getLineTop方法的具体用法?Java Layout.getLineTop怎么用?Java Layout.getLineTop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.Layout的用法示例。


在下文中一共展示了Layout.getLineTop方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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) {
    int st = ((Spanned) text).getSpanStart(this);
    int itop = layout.getLineTop(layout.getLineForOffset(st));

    if (dir < 0)
        x -= mBitmap.getWidth();

    int delta = totalHeight - mBitmap.getHeight();

    if (delta > 0) {
        if (mVerticalAlignment == ALIGN_TOP) {
            c.drawBitmap(mBitmap, x, itop, p);
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            c.drawBitmap(mBitmap, x, itop + delta / 2, p);
        } else {
            c.drawBitmap(mBitmap, x, itop + delta, p);
        }
    } else {
        c.drawBitmap(mBitmap, x, itop, p);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:SpanUtils.java

示例2: getScreenCoordsForPos

import android.text.Layout; //导入方法依赖的package包/类
private float[] getScreenCoordsForPos(int line, int pos)
{
	LayoutManager manager = getLayoutManager();
	ViewHolder holder = findViewHolderForAdapterPosition(line);
	if(holder == null)
	{
		if(getChildCount() > 0 && getChildAdapterPosition(getChildAt(getChildCount() - 1)) < line)
			return new float[]{getWidth() / 2, getHeight(), 0};
		return new float[]{getWidth() / 2, 0, 0};
	}
	View view = manager.findViewByPosition(findViewHolderForAdapterPosition(line).getLayoutPosition());
	if(view == null)
		return new float[]{0, 0, 0};
	Layout layout = ((TextView)view).getLayout();
	float x = layout.getPrimaryHorizontal(pos);
	int ln = layout.getLineForOffset(pos);
	float y = (float)(layout.getLineTop(ln) + layout.getLineBottom(ln)) / 2;
	float screenX = x + view.getLeft() + getScrollX();
	float screenY = y + view.getTop() + getScrollY();
	if(screenY < 0)
		screenY = 0;
	if(screenY > getBottom())
		screenY = getBottom();
	return new float[]{screenX, screenY, layout.getLineBottom(ln) - y};
}
 
开发者ID:mniip,项目名称:bananapeel,代码行数:26,代码来源:SelectableScrollbackView.java

示例3: 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

示例4: drawLeadingMargin

import android.text.Layout; //导入方法依赖的package包/类
public void drawLeadingMargin(final Canvas c, final Paint p, int x, final int dir,
                              final int top, final int baseline, final int bottom,
                              final CharSequence text, final int start, final int end,
                              final boolean first, final Layout layout) {
    int st = ((Spanned) text).getSpanStart(this);
    int itop = layout.getLineTop(layout.getLineForOffset(st));

    if (dir < 0)
        x -= mBitmap.getWidth();

    int delta = totalHeight - mBitmap.getHeight();

    if (delta > 0) {
        if (mVerticalAlignment == ALIGN_TOP) {
            c.drawBitmap(mBitmap, x, itop, p);
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            c.drawBitmap(mBitmap, x, itop + delta / 2, p);
        } else {
            c.drawBitmap(mBitmap, x, itop + delta, p);
        }
    } else {
        c.drawBitmap(mBitmap, x, itop, p);
    }
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:25,代码来源:SpanUtils.java

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

}
 
开发者ID:monolifed,项目名称:mininoteview,代码行数:24,代码来源:TextEdit.java

示例6: show

import android.text.Layout; //导入方法依赖的package包/类
public void show() {
    mTextView.getLocationInWindow(mTempCoors);
    Layout layout = mTextView.getLayout();
    int posX = (int) layout.getPrimaryHorizontal(mSelectionInfo.mStart) + mTempCoors[0];
    int posY = layout.getLineTop(layout.getLineForOffset(mSelectionInfo.mStart)) + mTempCoors[1] - mHeight - 16;
    if (posX <= 0) posX = 16;
    if (posY < 0) posY = 16;
    if (posX + mWidth > TextLayoutUtil.getScreenWidth(mContext)) {
        posX = TextLayoutUtil.getScreenWidth(mContext) - mWidth - 16;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mWindow.setElevation(8f);
    }
    mWindow.showAtLocation(mTextView, Gravity.NO_GRAVITY, posX, posY);
}
 
开发者ID:shenhuanet,项目名称:SelectableTextProvider,代码行数:16,代码来源:SelectableTextProvider.java

示例7: getTouchedSpan

import android.text.Layout; //导入方法依赖的package包/类
/**
 * Gets the span that was touched.
 * @param tv {@link TextView}
 * @param span {@link Spannable}
 * @param e {@link MotionEvent}
 * @return {@link TouchableSpan}
 */
private TouchableSpan getTouchedSpan(TextView tv, Spannable span, MotionEvent e) {
    // Find the location in which the touch was made
    int x = (int)e.getX();
    int y = (int)e.getY();

    // Ignore padding
    x -= tv.getTotalPaddingLeft();
    y -= tv.getTotalPaddingTop();

    // Account for scrollable text
    x += tv.getScrollX();
    y += tv.getScrollY();

    final Layout layout = tv.getLayout();
    final int touchedLine = layout.getLineForVertical(y);
    final int touchOffset = layout.getOffsetForHorizontal(touchedLine, x);

    // Set bounds of the touched line
    touchBounds.left = layout.getLineLeft(touchedLine);
    touchBounds.top = layout.getLineTop(touchedLine);
    touchBounds.right = layout.getLineRight(touchedLine);
    touchBounds.bottom = layout.getLineBottom(touchedLine);

    // Ensure the span falls within the bounds of the touch
    TouchableSpan touchSpan = null;
    if (touchBounds.contains(x, y)) {
        // Find clickable spans that lie under the touched area
        TouchableSpan[] spans = span.getSpans(touchOffset, touchOffset, TouchableSpan.class);
        touchSpan = (spans.length > 0) ? spans[0] : null;
    }

    return touchSpan;
}
 
开发者ID:tylersuehr7,项目名称:social-text-view,代码行数:41,代码来源:AccurateMovementMethod.java

示例8: isEventOnText

import android.text.Layout; //导入方法依赖的package包/类
/**
 * Check if event's coordinates are within line's text.
 *
 * Needed as getOffsetForHorizontal will return closest character,
 * which is an issue when clicking the empty space next to the text.
 */
private boolean isEventOnText(MotionEvent event, Layout layout, int line) {
    float left = layout.getLineLeft(line) + getTotalPaddingLeft();
    float right = layout.getLineRight(line) + getTotalPaddingRight();
    float bottom = layout.getLineBottom(line) + getTotalPaddingTop();
    float top = layout.getLineTop(line) + getTotalPaddingTop();

    return left <= event.getX() && event.getX() <= right &&
           top <= event.getY() && event.getY() <= bottom;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:16,代码来源:TextViewWithLinks.java

示例9: getDebugPosition

import android.text.Layout; //导入方法依赖的package包/类
/**
 * @param line   - current line
 * @param column - column of line
 * @return Position (in pixels) for edittext at line and column
 */
public Point getDebugPosition(int line, int column, int gravity) {
    Layout layout = getLayout();
    if (layout != null) {
        int pos = layout.getLineStart(line) + column;

        int baseline = layout.getLineBaseline(line);
        int ascent = layout.getLineAscent(line);

        int offsetHorizontal = (int) layout.getPrimaryHorizontal(pos) + mLinePadding; //x

        float y;
        int offsetVertical = 0;

        if (gravity == Gravity.BOTTOM) {
            y = baseline + ascent;
            if (verticalScroll != null) {
                offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY());
            } else {
                offsetVertical = (int) ((y + mCharHeight) - getScrollY());
            }
            return new Point(offsetHorizontal, offsetVertical);
        } else if (gravity == Gravity.TOP) {
            y = layout.getLineTop(line);
            if (verticalScroll != null) {
                offsetVertical = (int) (y - verticalScroll.getScrollY());
            } else {
                offsetVertical = (int) (y - getScrollY());
            }
            return new Point(offsetHorizontal, offsetVertical);
        }

        return new Point(offsetHorizontal, offsetVertical);
    }
    return new Point();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:41,代码来源:HighlightEditor.java

示例10: getLastLineHeight

import android.text.Layout; //导入方法依赖的package包/类
private int getLastLineHeight() {
    Layout layout = getLayout();
    if (layout != null) {
        int lineCount = layout.getLineCount();
        if (lineCount > 0) {
            //行的底部距离view顶部的高度, 最后一行的LineTop通常会等于View的height
            return layout.getLineTop(lineCount) - layout.getLineTop(lineCount - 1);
        }
    }
    return 0;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:12,代码来源:RExTextView.java

示例11: onTouchEvent

import android.text.Layout; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN ||
            action == MotionEvent.ACTION_MOVE ||
            action == MotionEvent.ACTION_CANCEL) {
        int x = (int) event.getX();
        int y = (int) event.getY();

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();

        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        ImageTextSpan[] link = buffer.getSpans(off, off, ImageTextSpan.class);

        if (link.length > 0) {
            ImageTextSpan imageTextSpan = link[0];
            int spanStart = buffer.getSpanStart(imageTextSpan);
            int spanEnd = buffer.getSpanEnd(imageTextSpan);
            int showTextLength = imageTextSpan.getShowTextLength();

            int top = layout.getLineTop(line);
            int bottom = layout.getLineTop(line + 1);
            float left = layout.getPrimaryHorizontal(spanStart);
            float right = layout.getPrimaryHorizontal(spanStart + showTextLength);

            if (imageTextSpan.isCanClick() && (x >= left && x <= right)   /*(off >= spanStart && off <= spanStart + showTextLength)*/) {
                if (action == MotionEvent.ACTION_UP) {
                    imageTextSpan.onTouchUp(widget);
                    imageTextSpan.onClick(widget);
                    isTouchInSpan = false;
                } else if (action == MotionEvent.ACTION_DOWN) {
                    isTouchInSpan = true;
                    imageTextSpan.onTouchDown(widget, event.getX(), event.getY());
                    if (showSelectionSpanBgColor) {
                        Selection.setSelection(buffer,
                                spanStart,
                                spanEnd);
                    }
                } else if (action == MotionEvent.ACTION_MOVE) {
                    //link[0].onTouchMove(widget, event.getX(), event.getY());
                    //return super.onTouchEvent(widget, buffer, event);
                } else {
                    isTouchInSpan = false;
                    imageTextSpan.onTouchCancel(widget, event.getX(), event.getY());
                    //return super.onTouchEvent(widget, buffer, event);
                }

            } else {
                Selection.removeSelection(buffer);
            }
            return isTouchInSpan;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:68,代码来源:RExTextView.java


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