本文整理了Java中android.text.Layout.getLineBaseline()
方法的一些代码示例,展示了Layout.getLineBaseline()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getLineBaseline()
方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getLineBaseline
暂无
代码示例来源:origin: stackoverflow.com
inputEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Layout layout = inputEditText.getLayout();
int pos = inputEditText.getSelectionStart();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int bottom = inputEditText.getHeight();
inputEditText.setDropDownVerticalOffset(baseline - bottom);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
代码示例来源:origin: hanks-zyh/HTextView
@Override
protected void drawFrame(Canvas canvas) {
Layout layout = mHTextView.getLayout();
int gapIndex = 0;
for (int i = 0; i < layout.getLineCount(); i++) {
int lineStart = layout.getLineStart(i);
int lineEnd = layout.getLineEnd(i);
float lineLeft = layout.getLineLeft(i);
float lineBaseline = layout.getLineBaseline(i);
String lineText = mText.subSequence(lineStart, lineEnd).toString();
for (int c = 0; c < lineText.length(); c++) {
int alpha = alphaList.get(gapIndex);
mPaint.setAlpha((int) ((255 - alpha) * progress + alpha));
canvas.drawText(String.valueOf(lineText.charAt(c)), lineLeft, lineBaseline, mPaint);
lineLeft += gapList.get(gapIndex++);
}
}
}
}
代码示例来源: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: 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: billthefarmer/editor
@Override
public boolean onQueryTextSubmit(String query)
{
// Find next text
if (matcher.find())
{
// Get index
index = matcher.start();
// Get text position
int line = textView.getLayout().getLineForOffset(index);
int pos = textView.getLayout().getLineBaseline(line);
// Scroll to it
scrollView.smoothScrollTo(0, pos - height / 2);
// Highlight it
editable.setSpan(span, matcher.start(), matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else
{
matcher.reset();
index = 0;
}
return true;
}
}
代码示例来源: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: billthefarmer/diary
.getLineForOffset(index);
int pos = textView.getLayout()
.getLineBaseline(line);
代码示例来源:origin: billthefarmer/diary
.getLineForOffset(index);
int pos = textView.getLayout()
.getLineBaseline(line);
代码示例来源:origin: billthefarmer/editor
.getLineForOffset(index);
int pos = textView.getLayout()
.getLineBaseline(line);
代码示例来源:origin: stackoverflow.com
Layout layout = _field.getLayout();
int line = layout.getLineForOffset(pos);
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
int x = (int)layout.getPrimaryHorizontal(pos);
代码示例来源:origin: TMLAndroid/FillBlankDemo
public RectF drawSpanRect(ReplaceSpan s) {
Layout layout = mTv.getLayout();
Spannable buffer = (Spannable) mTv.getText();
int l = buffer.getSpanStart(s);
int r = buffer.getSpanEnd(s);
int line = layout.getLineForOffset(l);
int l2 = layout.getLineForOffset(r);
if (mRf == null){
mRf = new RectF();
//Rect rt = new Rect();
Paint.FontMetrics fontMetrics = mTv.getPaint().getFontMetrics();
//mTv.getPaint().getTextBounds("TgQyYFJ",0,7,rt);
mFontT = (int) fontMetrics.ascent;
mFontB = (int) fontMetrics.descent;
}
mRf.left = layout.getPrimaryHorizontal(l);
mRf.right = layout.getSecondaryHorizontal(r);
// 通过基线去校准
line = layout.getLineBaseline(line);
mRf.top = line + mFontT;
mRf.bottom = line + mFontB;
return mRf;
}
代码示例来源:origin: ahmadaghazadeh/CodeEditor
int baseline = layout.getLineBaseline(line);
int ascent = layout.getLineAscent(line);
代码示例来源:origin: blurpy/kouchat-android
private static Point getCoordinatesForLine(final TextView textView, final String textToFind,
final int lineNumber, final String fullLine) {
final Layout layout = textView.getLayout();
final TextPaint paint = textView.getPaint();
final int textIndex = fullLine.indexOf(textToFind);
final String preText = fullLine.substring(0, textIndex);
final int textWidth = (int) Layout.getDesiredWidth(textToFind, paint);
final int preTextWidth = (int) Layout.getDesiredWidth(preText, paint);
final int[] textViewXYLocation = new int[2];
textView.getLocationOnScreen(textViewXYLocation);
// Width: in the middle of the text
final int xPosition = preTextWidth + (textWidth / 2);
// Height: in the middle of the given line, plus the text view position from the top, minus the amount scrolled
final int yPosition = layout.getLineBaseline(lineNumber) + textViewXYLocation[1] - textView.getScrollY();
return new Point(xPosition, yPosition);
}
代码示例来源: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);
}
}
代码示例来源:origin: ahmadaghazadeh/CodeEditor
if (number != prevLineNumber) {
canvas.drawText(Integer.toString(number + 1), textRight,
layout.getLineBaseline(i) + paddingTop, mLineNumberPaint);
代码示例来源:origin: Light-Team/ModPE-IDE-Source
if (number != prevLineNumber) {
canvas.drawText(Integer.toString(number + 1), textRight,
layout.getLineBaseline(i) + paddingTop, mLineNumberPaint);
代码示例来源:origin: lltvcn/FreeText
drawer.draw(canvas,getPaint(),left,layout.getLineTop(line)+getPaddingTop(), right ,layout.getLineBottom(line)+getPaddingTop(),layout.getLineBaseline(line));
代码示例来源:origin: lltvcn/FreeText
right+=getPaddingLeft();
drawer.draw(canvas,getPaint(),left,layout.getLineTop(line)+getPaddingTop(), right ,layout.getLineBottom(line)+getPaddingTop(),layout.getLineBaseline(line));
内容来源于网络,如有侵权,请联系作者删除!