我正在为Android 3.0平板电脑开发电子书阅读器应用程序.首先,我有一大块String数据.我想根据设备的屏幕大小将该字符串拆分/拆分为页面[我打算使用文本切换器或查看翻板].虽然我尝试使用getWindowManager()方法,但我无法获得首选结果.
在下面的线程中提到Text Switcher会根据屏幕大小自动中断文本.但是我不这么认为. 在Android应用程序中管理文本,就像在电子书中一样
这是我使用的逻辑:
// retreiving the flipper
flipper = (ViewFlipper) findViewById(R.id.new_view_flipper);
// obtaining screen dimensions
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
// contentString is the whole string of the book
while (contentString != null && contentString.length() != 0)
{
totalPages ++;
// creating new textviews for every page
TextView contentTextView = new TextView(this);
contentTextView.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
contentTextView.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
contentTextView.setMaxHeight(screenHeight);
contentTextView.setMaxWidth(screenWidth);
float textSize = contentTextView.getTextSize();
Paint paint = new Paint();
paint.setTextSize(textSize);
int numChars = 0; …Run Code Online (Sandbox Code Playgroud)