Ebook reader pagination issue in android

老子叫甜甜 提交于 2019-12-11 02:27:52

问题


I am creating an ebook reader for android. I got problems when the content is broken in to pages.

Here are 3 screenshots of my app.

As you can see the content is not perfectly fit to the screen. For example the last sentence should have been completed on the first image without jumping onto the next page. Also the image of the third pic should have come to the latter part of the second image since there is enough space. In some pages the content goes underneath the navigation bar as well.

The logic is : I get the entire content and when a space is found get the previous word and then check whether the text height is larger than the screen height. If not again check for the next space and append the next word to the previously collected string. Likewise I get the page content.

The code to get the textHeight is as follows,

    public int getTextHeight(final String text) {
     TextView textView = new TextView(getContext());
     textView.setText(text);
     textView.setTextSize(TEXT_SIZE);
     TextPaint textPaint = textView.getPaint();
     return new StaticLayout(text.toString(), textPaint, getScreenWidth(),Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true).getHeight();
    }

Code for Screen height ,

    public int getScreenHeight() {
      WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
      wm.getDefaultDisplay().getMetrics(dm);
      return dm.heightPixels;
    }    

** Since there is a navigation bar at the bottom I reduced 50 pixels from the screen height. But still the content goes underneath the navigation bar.

So my questions are,

  1. How to hide the navigation bar or If it can not be hidden then how to get the exact height of it
  2. What is the reason for the content not to fit on the screen, I really can't find the reason for this. (I checked with a ebook that has only text, there are some white space at the bottom, but didn't go underneath the bar)

**I put 300 px height for images. Used ViewPager for implementation.

Thanks.

来源:https://stackoverflow.com/questions/25961614/ebook-reader-pagination-issue-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!