问题
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,
- How to hide the navigation bar or If it can not be hidden then how to get the exact height of it
- 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