Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android的多个页面中显示长文本视图(字符串)_Android_Textview - Fatal编程技术网

如何在android的多个页面中显示长文本视图(字符串)

如何在android的多个页面中显示长文本视图(字符串),android,textview,Android,Textview,我正在开发一个看起来像电子书阅读器的应用程序(.text,pdf文件等)。我有一个巨大的文本,分为不同的章节或页面 现在的问题是如何将整个内容分成若干页,并逐个显示这些页。我怎么知道屏幕中要容纳的字符数(取决于屏幕大小和字体大小)。我完全不知道从哪里开始,如何继续。请给我举个例子来帮助我。这里是如何做的。它使用单个滚动视图来显示长文本字符串。但是,滚动手势被覆盖。因此,当你做“向左滑动手势”时,它会做翻页动画,并向下滚动视图(按屏幕高度)。因此,当您手动滚动到视图底部时,用户感觉页面好像已经翻了

我正在开发一个看起来像电子书阅读器的应用程序(.text,pdf文件等)。我有一个巨大的文本,分为不同的章节或页面


现在的问题是如何将整个内容分成若干页,并逐个显示这些页。我怎么知道屏幕中要容纳的字符数(取决于屏幕大小和字体大小)。我完全不知道从哪里开始,如何继续。请给我举个例子来帮助我。

这里是如何做的。它使用单个滚动视图来显示长文本字符串。但是,滚动手势被覆盖。因此,当你做“向左滑动手势”时,它会做翻页动画,并向下滚动视图(按屏幕高度)。因此,当您手动滚动到视图底部时,用户感觉页面好像已经翻了。英根纽斯,不是吗?而且你不必担心字体大小、段落间距、字数被剪切等问题。该应用程序在上可用。

这里是一个简单的示例应用程序,以备其他人需要

导入android.content.Context;
导入android.os.AsyncTask;
导入android.text.TextPaint;
公共类PagerTask扩展异步任务{
私有上下文;
公共页面任务(上下文){
this.mContext=上下文;
}
受保护的空白背景(主活动.视图和绘制…vps){
MainActivity.ViewAndPaint vp=vps[0];
MainActivity.ProgressTracker progress=新的MainActivity.ProgressTracker();
TextPaint paint=vp.paint;
int numChars=0;
int lineCount=0;
int maxLineCount=vp.maxLineCount;
整数totalCharactersProcessedSoFar=0;
//contentString是整本书的字符串
int totalPages=0;
while(vp.contentString!=null&&vp.contentString.length()!=0)
{
而((lineCount

使用
ViewFlipper
ViewPager
显示页面并在页面之间滑动them@Prosanto你解决这个问题了吗?如果你解决了这个问题,请帮助我。我正在使用相同的功能。我不知道从哪里开始,如何继续。请帮帮我
import android.content.Context;
import android.os.AsyncTask;
import android.text.TextPaint;

public class PagerTask extends AsyncTask<MainActivity.ViewAndPaint,      MainActivity.ProgressTracker, Void> {

private Context mContext;

public PagerTask(Context context){
    this.mContext = context;
}

protected Void doInBackground(MainActivity.ViewAndPaint... vps) {

    MainActivity.ViewAndPaint vp = vps[0];
    MainActivity.ProgressTracker progress = new MainActivity.ProgressTracker();
    TextPaint paint = vp.paint;
    int numChars = 0;
    int lineCount = 0;
    int maxLineCount = vp.maxLineCount;
    int totalCharactersProcessedSoFar = 0;

    // contentString is the whole string of the book
    int totalPages = 0;
    while (vp.contentString != null && vp.contentString.length() != 0 )
    {
        while ((lineCount < maxLineCount) && (numChars < vp.contentString.length())) {
            numChars = numChars + paint.breakText(vp.contentString.substring(numChars), true, vp.screenWidth, null);
            lineCount ++;
        }

        // Retrieve the String to be displayed in the current textview
        String stringToBeDisplayed = vp.contentString.substring(0, numChars);
        int nextIndex = numChars;
        char nextChar = nextIndex < vp.contentString.length() ? vp.contentString.charAt(nextIndex) : ' ';
        if (!Character.isWhitespace(nextChar)) {
            stringToBeDisplayed = stringToBeDisplayed.substring(0, stringToBeDisplayed.lastIndexOf(" "));
        }
        numChars = stringToBeDisplayed.length();
        vp.contentString = vp.contentString.substring(numChars);

        // publish progress
        progress.totalPages = totalPages;
        progress.addPage(totalPages, totalCharactersProcessedSoFar, totalCharactersProcessedSoFar + numChars);
        publishProgress(progress);

        totalCharactersProcessedSoFar += numChars;

        // reset per page items
        numChars = 0;
        lineCount = 0;

        // increment  page counter
        totalPages ++;
    }

    return null;
}

    @Override
    protected void onProgressUpdate(MainActivity.ProgressTracker... values) {
        ((MainActivity)mContext).onPageProcessedUpdate(values[0]);
    }

}