title: Android: How to display text on multiple pages in a pleasant way (viewflipper)
body: <p>I need to create an eBook reader for an exam:</p>
  
  <p>When we click on a file..</p>
  
  <pre><code>private void onFileClick(Option o){
      Toast.makeText(this, "File Clicked: "+o.getName(), Toast.LENGTH_SHORT).show();
  
      BookView.readBook(o);
  
      Intent intent = new Intent(this,BookView.class);
  
      this.startActivityForResult(intent, 1000);  
  
  
  }
  </code></pre>
  
  <p>Then we read the contents of text file:</p>
  
  <pre><code>static void readBook(Option o){
  
      try{
  
         File f = new    File(Environment.getExternalStorageDirectory()+"/"+o.getName());
  
         FileInputStream fileIS = new FileInputStream(f);
  
         BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
  
         String readString = new String();
  
         int i = 0; 
  
         monArrayList.clear();
  
         stringBuilder = new StringBuilder();
  
         while((readString = buf.readLine())!= null){
  
            i=i+1;
  
            int stringLength = stringBuilder.length();
  
            stringBuilder.append(readString);
  
            if(stringLength&gt;=1040){
              monArrayList.add(new String(stringBuilder));
              stringBuilder.setLength(0);
            }    
         }
  
      } catch (FileNotFoundException e) {
  
         e.printStackTrace();
  
      } catch (IOException e){
  
         e.printStackTrace();
  
      }
  }
  </code></pre>
  
  <p>Then we start the activity:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      detector        = new GestureDetector(this,this);
      view1           = (ViewFlipper)findViewById(R.id.flipper);
  
      Iterator&lt;String&gt; iterator = monArrayList.iterator();
      while (iterator.hasNext()) {
        String element = iterator.next();
        view1.addView(createTextView(element));
      }
  
      view1.addView(createTextView(stringBuilder));
  
      slideLeftIn     = AnimationUtils.loadAnimation(this, R.anim.slide_left_in); 
      slideLeftOut    = AnimationUtils.loadAnimation(this, R.anim.slide_left_out); 
      slideRightIn    = AnimationUtils.loadAnimation(this, R.anim.slide_right_in); 
      slideRightOut   = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);   
  
      layout = new LinearLayout(this);
      layout.setOrientation(LinearLayout.VERTICAL);
      BitmapDrawable bmp = (BitmapDrawable)this.getResources().getDrawable(R.drawable.back);
      layout.setBackgroundDrawable(bmp);
      layout.setPadding(20, 20, 20, 20);
  
  }
  </code></pre>
  
  <p>Currently it works, but it is not pretty. I saved my book pages into an ArrayList by limiting the record to 1040 characters.</p>
  
  <p>The pages are not fulfilled intelligently (some pages are at just 3/4). This is due to the fact that my program does not include detection of line feed and carriage return ..</p>
  
  <p>I would like to adapt my text to my textView, so that they coincide.</p>
  
  <p><strong>How do I know how much text can fit in my textView (my page)?</strong></p>
  
  <p>Thank you</p>