当前位置: 首页>>代码示例>>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;未经允许,请勿转载。