本文整理了Java中android.text.Layout.getLineAscent()
方法的一些代码示例,展示了Layout.getLineAscent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getLineAscent()
方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getLineAscent
暂无
代码示例来源:origin: stackoverflow.com
int pos = editText.getSelectionStart();
Layout layout = editText.getLayout();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
float x = layout.getPrimaryHorizontal(pos);
float y = baseline + ascent;
代码示例来源:origin: facebook/TextLayoutBuilder
/**
* Prior to version 20, If the Layout specifies extra space between lines (either by spacingmult
* or spacingadd) the StaticLayout would erroneously add this space after the last line as well.
* This bug was fixed in version 20. This method calculates the extra space and reduces the height
* by that amount.
*
* @param layout The layout.
* @return The height of the layout.
*/
public static int getHeight(Layout layout) {
if (layout == null) {
return 0;
}
int extra = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH
&& layout instanceof StaticLayout) {
int line = Math.max(0, layout.getLineCount() - 1);
int above = layout.getLineAscent(line);
int below = layout.getLineDescent(line);
float originalSize = (below - above - layout.getSpacingAdd()) / layout.getSpacingMultiplier();
float ex = below - above - originalSize;
if (ex >= 0) {
extra = (int) (ex + 0.5);
} else {
extra = -(int) (-ex + 0.5);
}
}
return layout.getHeight() - extra;
}
代码示例来源:origin: stackoverflow.com
Layout layout = etShell.getLayout();
int pos = etShell.length();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
float x = layout.getPrimaryHorizontal(pos);
float y = baseline + ascent;
etInput.setMaxWidth(width - (int) x);
etInput.setX(x);
etInput.setY(y);
代码示例来源:origin: stackoverflow.com
if(getText().toString().substring(start,end).indexOf("\t")>=0
|| getText().toString().substring(start,end).indexOf("\n")>=0
|| getText().toString().substring(start,end).indexOf("\r")>=0) {
TextPaint paint = new TextPaint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(mBackgroundColor);
paint.bgColor = mBackgroundColor;
Layout layout = getLayout();
int line = layout.getLineForOffset(start);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
float x = layout.getPrimaryHorizontal(start);
float y = baseline + ascent;
Rect rect = new Rect();
//rect.set(start, 0, Math.round(layout.getSecondaryHorizontal(end)), getLineHeight()+5);
rect.set(start, 0, Math.round(layout.getSecondaryHorizontal(end)), getLineHeight()+5);
rect.offset(Math.round(x), Math.round(y));
Log.d("debug","tabs " + rect.toString());
canvas.drawRect(rect, paint);
}
代码示例来源:origin: stackoverflow.com
public void setCursorLocation(int characterOffset) {
Layout layout = this.getLayout();
int line = layout.getLineForOffset(characterOffset);
mCursorX = layout.getPrimaryHorizontal(characterOffset);
mCursorBaseY = layout.getLineBaseline(line);
mCursorBottomY = layout.getLineBottom(line);
mCursorAscentY = layout.getLineAscent(line);
this.invalidate();
}
代码示例来源:origin: ywwynm/EverythingDone
public static int getCursorY(EditText et) {
int pos = et.getSelectionStart();
Layout layout = et.getLayout();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
return baseline + ascent;
}
}
代码示例来源:origin: stackoverflow.com
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
int x = (int)layout.getPrimaryHorizontal(pos);
int y = baseline + ascent;
代码示例来源:origin: ahmadaghazadeh/CodeEditor
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
代码示例来源:origin: Light-Team/ModPE-IDE-Source
protected void onPopupChangePosition() {
try {
Layout layout = getLayout();
if (layout != null) {
int pos = getSelectionStart();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
float x = layout.getPrimaryHorizontal(pos);
float y = baseline + ascent;
int offsetHorizontal = (int) x + mGutterWidth;
setDropDownHorizontalOffset(offsetHorizontal);
int heightVisible = getHeightVisible();
int offsetVertical = (int) ((y + mCharHeight) - getScrollY());
int tmp = offsetVertical + getDropDownHeight() + mCharHeight;
if (tmp < heightVisible) {
tmp = offsetVertical + mCharHeight / 2;
setDropDownVerticalOffset(tmp);
} else {
tmp = offsetVertical - getDropDownHeight() - mCharHeight;
setDropDownVerticalOffset(tmp);
}
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
内容来源于网络,如有侵权,请联系作者删除!