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

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

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

Layout.getLineMax介绍

暂无

代码示例

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

.getTextBounds(customEllipsisText.toString(), 0, customEllipsisText.length(), bounds);
final float ellipsisTarget = newLayout.getLineMax(ellipsizedLineNumber) - bounds.width();

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

/**
 * Calculate the right boundary for this run (harder than it sounds). As we're a letter ahead,
 * need to grab either current letter start or the end of the previous line. Also need to
 * consider maxLines case, which inserts ellipses at the overflow point – don't include these.
 */
private int getRunRight(
    Layout unrestrictedLayout, Layout maxLinesLayout, int currentLine, int index,
    int line, boolean withinMax, boolean isMaxEllipsis, boolean isLastChar) {
  int runRight;
  if (line != currentLine || isLastChar) {
    if (isMaxEllipsis) {
      runRight = (int) maxLinesLayout.getPrimaryHorizontal(index);
    } else {
      runRight = (int) unrestrictedLayout.getLineMax(currentLine);
    }
  } else {
    if (withinMax) {
      runRight = (int) maxLinesLayout.getPrimaryHorizontal(index);
    } else {
      runRight = (int) unrestrictedLayout.getPrimaryHorizontal(index);
    }
  }
  return runRight;
}

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

mText = (EditText) findViewById(R.id.editText1);
OnTouchListener otl = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    Layout layout = ((EditText) v).getLayout();
    float x = event.getX() + mText.getScrollX();
    int offset = layout.getOffsetForHorizontal(0, x);
    if(offset>0)
      if(x>layout.getLineMax(0))
        mText.setSelection(offset);     // touch was at end of text
      else
        mText.setSelection(offset - 1);
    break;
    }
  return true;
  }
};
mText.setOnTouchListener(otl);

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

setOnTouchListener(new View.OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     switch (event.getAction()) {
       case MotionEvent.ACTION_DOWN:
         Layout layout = ((EditText) v).getLayout();
         float x = event.getX() + getScrollX();
         int offset = layout.getOffsetForHorizontal(0, x);
         if (offset > 0)
           if (x > layout.getLineMax(0))
             setSelection(offset);     
           else
             setSelection(offset - 1);
         break;
     }
     return true;
   }
 });

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

mText = (EditText) findViewById(R.id.editText1);
OnTouchListener otl = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    Layout layout = ((EditText) v).getLayout();
    float x = event.getX() + mText.getScrollX();
    int offset = layout.getOffsetForHorizontal(0, x);
    if(offset>0)
      if(x>layout.getLineMax(0))
        mText.setSelection(offset);     // touch was at end of text
      else
        mText.setSelection(offset - 1);
    break;
    }
  return true;
  }
};
mText.setOnTouchListener(otl);

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

mText = (EditText) findViewById(R.id.editText1);
OnTouchListener otl = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    Layout layout = ((EditText) v).getLayout();
    float x = event.getX() + mText.getScrollX();
    int offset = layout.getOffsetForHorizontal(0, x);
    if(offset>0)
      if(x>layout.getLineMax(0))
        mText.setSelection(offset);     // touch was at end of text
      else
        mText.setSelection(offset - 1);
    break;
    }
  return true;
  }
};
mText.setOnTouchListener(otl);

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

mText = (EditText) findViewById(R.id.editText1);
OnTouchListener otl = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    Layout layout = ((EditText) v).getLayout();
    float x = event.getX() + mText.getScrollX();
    int offset = layout.getOffsetForHorizontal(0, x);
    if(offset>0)
      if(x>layout.getLineMax(0))
        mText.setSelection(offset);     // touch was at end of text
      else
        mText.setSelection(offset - 1);
    break;
    }
  return true;
  }
};
mText.setOnTouchListener(otl);

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

OnTouchListener otl = new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
      Layout layout = ((EditText) v).getLayout();
      float x = event.getX() + secondText.getScrollX();
      int offset = layout.getOffsetForHorizontal(0, x);
      if(offset>0)
        if(x>layout.getLineMax(0))
          secondText.setSelection(offset);     // touch was at end of text
        else
          secondText.setSelection(offset - 1);
      break;
      }
    return true;
    }
  };
  secondText.setOnTouchListener(otl);

代码示例来源:origin: aliumujib/Nibo

@Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mCustomKeyboardView.setVisibility(View.VISIBLE);
        mCustomKeyboardView.setEnabled(true);
        Layout layout = ((EditText) v).getLayout();
        float x = event.getX() + mSearchEditText.getScrollX();
        int offset = layout.getOffsetForHorizontal(0, x);
        if (offset > 0)
          if (x > layout.getLineMax(0))
            mSearchEditText.setSelection(offset);     // Touch was at the end of the text
          else
            mSearchEditText.setSelection(offset - 1);
        break;
      case MotionEvent.ACTION_MOVE:
        layout = ((EditText) v).getLayout();
        x = event.getX() + mSearchEditText.getScrollX();
        offset = layout.getOffsetForHorizontal(0, x);
        if (offset > 0)
          if (x > layout.getLineMax(0))
            mSearchEditText.setSelection(offset);     // Touch point was at the end of the text
          else
            mSearchEditText.setSelection(offset - 1);
        break;
    }
    return true;
  }
};

代码示例来源:origin: hylinux1024/Componentization

public int getCursorPosition(MotionEvent event) {
  if (event == null) {
    return 0;
  }
  Layout layout = this.getLayout();
  float x = event.getX() + this.getScrollX();
  float y = event.getY() + this.getScrollY() - getTotalPaddingTop();
  int line = layout.getLineForVertical((int) y);
  int offset = layout.getOffsetForHorizontal(line, x);
  return offset > 0 ? (x > layout.getLineMax(line) ? offset : offset - 1) : offset;
}

代码示例来源:origin: adafruit/Bluefruit_LE_Connect_Android

int offset = layout.getOffsetForHorizontal(0, x);
if (offset > 0) {
  if (x > layout.getLineMax(0))
    editText.setSelection(offset);
  else

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

int offset = layout.getOffsetForHorizontal(0, x);
if(offset>0)
  if(x>layout.getLineMax(0))

代码示例来源:origin: ywwynm/EverythingDone

if (x > layout.getLineMax(line)) {
  et.setSelection(offset);
} else et.setSelection(offset - 1);

相关文章