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


Java Layout.getLineLeft方法代码示例

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


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

示例1: getPressedSpan

import android.text.Layout; //导入方法依赖的package包/类
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
    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 off = layout.getOffsetForHorizontal(line, x);
    if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) {
        // 实际上没点到任何内容
        off = -1;
    }

    ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class);
    ITouchableSpan touchedSpan = null;
    if (link.length > 0) {
        touchedSpan = link[0];
    }
    return touchedSpan;
}
 
开发者ID:coopese,项目名称:qmui,代码行数:26,代码来源:QMUILinkTouchDecorHelper.java

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

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

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

示例5: getStartOffsetLeft

import android.text.Layout; //导入方法依赖的package包/类
private int getStartOffsetLeft(@Nonnull Layout startLayout, int currentStartLine) {
    return (int) startLayout.getLineLeft(currentStartLine);
}
 
开发者ID:shazam,项目名称:reflow-animator,代码行数:4,代码来源:ReflowTextAnimatorHelper.java

示例6: reactTagForTouch

import android.text.Layout; //导入方法依赖的package包/类
@Override
public int reactTagForTouch(float touchX, float touchY) {
  Spanned text = (Spanned) getText();
  int target = getId();

  int x = (int) touchX;
  int y = (int) touchY;

  Layout layout = getLayout();
  if (layout == null) {
    // If the layout is null, the view hasn't been properly laid out yet. Therefore, we can't find
    // the exact text tag that has been touched, and the correct tag to return is the default one.
    return target;
  }
  int line = layout.getLineForVertical(y);

  int lineStartX = (int) layout.getLineLeft(line);
  int lineEndX = (int) layout.getLineRight(line);

  // TODO(5966918): Consider extending touchable area for text spans by some DP constant
  if (x >= lineStartX && x <= lineEndX) {
    int index = layout.getOffsetForHorizontal(line, x);

    // We choose the most inner span (shortest) containing character at the given index
    // if no such span can be found we will send the textview's react id as a touch handler
    // In case when there are more than one spans with same length we choose the last one
    // from the spans[] array, since it correspond to the most inner react element
    ReactTagSpan[] spans = text.getSpans(index, index, ReactTagSpan.class);

    if (spans != null) {
      int targetSpanTextLength = text.length();
      for (int i = 0; i < spans.length; i++) {
        int spanStart = text.getSpanStart(spans[i]);
        int spanEnd = text.getSpanEnd(spans[i]);
        if (spanEnd > index && (spanEnd - spanStart) <= targetSpanTextLength) {
          target = spans[i].getReactTag();
          targetSpanTextLength = (spanEnd - spanStart);
        }
      }
    }
  }

  return target;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:45,代码来源:ReactTextView.java


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