当前位置: 首页>>代码示例>>Java>>正文


Java Layout.getLineForOffset方法代码示例

本文整理汇总了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};
}
 
开发者ID:mniip,项目名称:bananapeel,代码行数:26,代码来源:SelectableScrollbackView.java

示例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
    }
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:32,代码来源:LModEditor.java

示例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);
			}
		}						 
	}
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:30,代码来源:ScrollingStrategy.java

示例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) {
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:37,代码来源:HighlightEditor.java

示例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;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:14,代码来源:RichEditText.java

示例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;
}
 
开发者ID:shenhuanet,项目名称:SelectableTextProvider,代码行数:4,代码来源:TextLayoutUtil.java


注:本文中的android.text.Layout.getLineForOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。