本文整理匯總了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;
}