本文整理匯總了Java中android.text.Layout.getLineForOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java Layout.getLineForOffset方法的具體用法?Java Layout.getLineForOffset怎麽用?Java Layout.getLineForOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.Layout
的用法示例。
在下文中一共展示了Layout.getLineForOffset方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getScreenCoordsForPos
import android.text.Layout; //導入方法依賴的package包/類
private float[] getScreenCoordsForPos(int line, int pos)
{
LayoutManager manager = getLayoutManager();
ViewHolder holder = findViewHolderForAdapterPosition(line);
if(holder == null)
{
if(getChildCount() > 0 && getChildAdapterPosition(getChildAt(getChildCount() - 1)) < line)
return new float[]{getWidth() / 2, getHeight(), 0};
return new float[]{getWidth() / 2, 0, 0};
}
View view = manager.findViewByPosition(findViewHolderForAdapterPosition(line).getLayoutPosition());
if(view == null)
return new float[]{0, 0, 0};
Layout layout = ((TextView)view).getLayout();
float x = layout.getPrimaryHorizontal(pos);
int ln = layout.getLineForOffset(pos);
float y = (float)(layout.getLineTop(ln) + layout.getLineBottom(ln)) / 2;
float screenX = x + view.getLeft() + getScrollX();
float screenY = y + view.getTop() + getScrollY();
if(screenY < 0)
screenY = 0;
if(screenY > getBottom())
screenY = getBottom();
return new float[]{screenX, screenY, layout.getLineBottom(ln) - y};
}
示例2: onPopupChangePosition
import android.text.Layout; //導入方法依賴的package包/類
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 + mLeftPadding;
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 ignored) {
//nothing
}
}
示例3: updatePosition
import android.text.Layout; //導入方法依賴的package包/類
public void updatePosition() {
if ( storedPosition == -1 && this.storedPercentage == -1d ) {
return; //Hopefully come back later
}
if ( childView.getText().length() == 0 ) {
return;
}
if ( storedPercentage != -1d ) {
this.storedPosition = (int) (this.childView.getText().length() * storedPercentage);
this.storedPercentage = -1d;
}
Layout layout = this.childView.getLayout();
if ( layout != null ) {
int pos = Math.max(0, this.storedPosition);
int line = layout.getLineForOffset(pos);
if ( line > 0 ) {
int newPos = layout.getLineBottom(line -1);
bookView.scrollTo(0, newPos);
} else {
bookView.scrollTo(0, 0);
}
}
}
示例4: onPopupChangePosition
import android.text.Layout; //導入方法依賴的package包/類
@Override
public 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 + mLinePadding;
setDropDownHorizontalOffset(offsetHorizontal);
int heightVisible = getHeightVisible();
int offsetVertical = 0;
if (verticalScroll != null) {
offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY());
} else {
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 ignored) {
}
}
示例5: getCurrentCursorLine
import android.text.Layout; //導入方法依賴的package包/類
/**
* 獲取光標所在行數,對應段落
*
* @return 光標所在行數 0,1,2,3
*/
private int getCurrentCursorLine() {
int selectionStart = getSelectionStart();
Layout layout = getLayout();
if (selectionStart != -1) {
return layout.getLineForOffset(selectionStart);
}
return -1;
}
示例6: isEndOfLineOffset
import android.text.Layout; //導入方法依賴的package包/類
private static boolean isEndOfLineOffset(Layout layout, int offset) {
return offset > 0 && layout.getLineForOffset(offset) == layout.getLineForOffset(offset - 1) + 1;
}