本文整理汇总了Java中android.text.StaticLayout.getLineForOffset方法的典型用法代码示例。如果您正苦于以下问题:Java StaticLayout.getLineForOffset方法的具体用法?Java StaticLayout.getLineForOffset怎么用?Java StaticLayout.getLineForOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.StaticLayout
的用法示例。
在下文中一共展示了StaticLayout.getLineForOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcuPageOffsetOneChapter
import android.text.StaticLayout; //导入方法依赖的package包/类
private void calcuPageOffsetOneChapter(List<Content> chapter) {
int boundedWidth = (int) mWidth;
StaticLayout layout = StaticLayoutFactory.create(spannableStringBuilder,
PagetSizeConfig.getPaint(), boundedWidth, PagetSizeConfig.getLineSpacing());
layout.draw(new Canvas());
int pageHeight = (int) PagetSizeConfig.getPageHeight(mBookView.getContext());
Log.d(TAG, "Calcu page width = " + boundedWidth + ", height = " + pageHeight);
int totalLines = layout.getLineCount();
int topLineNextPage = -1;
int pageStartOffset = 0;
while (topLineNextPage < totalLines - 1) {
Log.d(TAG, "Processing line " + topLineNextPage + " / " + totalLines);
int topLine = layout.getLineForOffset(pageStartOffset);
topLineNextPage = layout.getLineForVertical(layout.getLineTop(topLine) + pageHeight);
Log.d(TAG, "topLine " + topLine + " / " + topLineNextPage);
if (topLineNextPage == topLine) {
//If lines are bigger than can fit on a page
topLineNextPage = topLine + 1;
}
int pageEnd = layout.getLineEnd(topLineNextPage - 1);
Log.d(TAG, "pageStartOffset=" + pageStartOffset + ", pageEnd=" + pageEnd);
if (pageEnd > pageStartOffset) {
if (spannableStringBuilder.subSequence(pageStartOffset, pageEnd).toString().trim().length() > 0) {
PageIndex pageIndex = findPageIndexByOffset(chapter, pageStartOffset);
Log.d(TAG, "add pageIndex :" + pageIndex.getIndex());
mPageIndices.add(pageIndex);
}
pageStartOffset = layout.getLineStart(topLineNextPage);
}
}
}
示例2: setCurrentLayout
import android.text.StaticLayout; //导入方法依赖的package包/类
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) {
currentLayout = layout;
currentLine = layout.getLineForOffset(start);
lastTop = -1;
heightOffset = yOffset;
}