android.text.Layout.getLineForVertical()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中android.text.Layout.getLineForVertical()方法的一些代码示例,展示了Layout.getLineForVertical()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getLineForVertical()方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getLineForVertical

Layout.getLineForVertical介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

int height    = myTextView.getHeight();
int scrollY   = myTextView.getScrollY();
Layout layout = myTextView.getLayout();

int firstVisibleLineNumber = layout.getLineForVertical(scrollY);
int lastVisibleLineNumber  = layout.getLineForVertical(scrollY+height);

代码示例来源:origin: stackoverflow.com

Layout layout = this.getLayout();
if (layout != null)
{
  int line = layout.getLineForVertical(y);
  int offset = layout.getOffsetForHorizontal(line, x);

  // At this point, "offset" should be what you want - the character index
}

代码示例来源:origin: stackoverflow.com

manip.setOnTouchListener(new View.OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
    Layout layout = ((TextView) v).getLayout();
    int x = (int)event.getX();
    int y = (int)event.getY();
    if (layout!=null){
      int line = layout.getLineForVertical(y);
      int offset = layout.getOffsetForHorizontal(line, x);
      Log.v("index", ""+offset);
    }
    return true;
  }
});

代码示例来源:origin: rey5137/material

protected int getLineAtCoordinate(float y) {
  y -= getTotalPaddingTop();
  // Clamp the position to inside of the view.
  y = Math.max(0.0f, y);
  y = Math.min(getHeight() - getTotalPaddingBottom() - 1, y);
  y += getScrollY();
  return getLayout().getLineForVertical((int) y);
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: nickbutcher/plaid

private TouchableUrlSpan 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);
  TouchableUrlSpan[] link = spannable.getSpans(off, off, TouchableUrlSpan.class);
  TouchableUrlSpan touchedSpan = null;
  if (link.length > 0) {
    touchedSpan = link[0];
  }
  return touchedSpan;
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

myTextView.setOnTouchListener(new OnTouchListener() {
     @Override
     public boolean onTouch(View v, MotionEvent event) {
       boolean ret = false;
       CharSequence text = ((TextView) v).getText();
       Spannable stext = Spannable.Factory.getInstance().newSpannable(text);
       TextView widget = (TextView) v;
       int action = event.getAction();
       if (action == MotionEvent.ACTION_UP ||
           action == MotionEvent.ACTION_DOWN) {
         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);
         ClickableSpan[] link = stext.getSpans(off, off, ClickableSpan.class);
         if (link.length != 0) {
           if (action == MotionEvent.ACTION_UP) {
             link[0].onClick(widget);
           }
           ret = true;
         }
       }
       return ret;
     }
   });

代码示例来源:origin: stackoverflow.com

public abstract class TextViewLinkHandler extends LinkMovementMethod {

  public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_UP)
      return super.onTouchEvent(widget, buffer, event);

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

    URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
    if (link.length != 0) {
      onLinkClick(link[0].getURL());
    }
    return true;
  }

  abstract public void onLinkClick(String url);
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: seven332/EhViewer

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

代码示例来源:origin: hidroh/materialistic

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: seven332/EhViewer

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

代码示例来源:origin: PrivacyApps/html-textview

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

代码示例来源:origin: jaydenxiao2016/AndroidFire

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

代码示例来源:origin: Naoki2015/CircleDemo

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: seven332/EhViewer

int areabot = areatop + widget.getHeight() - padding;
int linetop = layout.getLineForVertical(areatop);
int linebot = layout.getLineForVertical(areabot);

代码示例来源:origin: facebook/litho

private int getTextOffsetAt(int x, int y) {
 final int line = mLayout.getLineForVertical(y);

相关文章