【问题标题】:How to do pagination of text in Android TextView如何在 Android TextView 中对文本进行分页
【发布时间】:2012-12-19 14:46:49
【问题描述】:

我想在TextView 中查看长数据。我正在尝试使用以下代码进行分页:

TextPaint textPaint = tv.getPaint();
int boundedWidth = tv.getWidth();

StaticLayout layout = new StaticLayout(data, textPaint, boundedWidth , Alignment.ALIGN_NORMAL, 1.0f, 1, false);
layout.draw(new Canvas());

int totalLines = layout.getLineCount();
int currentPageNum = 0;
int topLine = 0;
int bottomLine = 0;

topLine = layout.getLineForVertical( currentPageNum * height );
bottomLine = layout.getLineForVertical( (currentPageNum + 1) * height );

int pageOffset = layout.getLineStart(topLine);
int pageEnd = layout.getLineEnd(bottomLine);

tv.setText(data.subSequence(pageOffset, pageEnd));

但是 pageoffsetpageend 给我的 startline+1endline+1 值不是应该绘制的文本的确切偏移量。

我的代码有什么问题?还有其他方法吗?

【问题讨论】:

    标签: android text pagination textview


    【解决方案1】:

    我终于让它工作了。我的 boundedWidth 为零,所以它返回错误数据的原因。

    【讨论】:

      猜你喜欢
      • 2014-06-05
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 2012-06-21
      • 1970-01-01
      相关资源
      最近更新 更多