當前位置: 首頁>>代碼示例>>Java>>正文


Java StaticLayout.getLineForOffset方法代碼示例

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

    }
 
開發者ID:ceji-longquan,項目名稱:ceji_android,代碼行數:45,代碼來源:PageCounter.java

示例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;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:7,代碼來源:LinkPath.java


注:本文中的android.text.StaticLayout.getLineForOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。