Sono in procinto di sviluppare un'applicazione di lettura di e-book per tablet Android 3.0. Per cominciare, ho una grande quantità di dati String. Voglio suddividere/suddividere quella stringa in pagine in base alle dimensioni dello schermo del dispositivo [Sto pensando di utilizzare il commutatore di testo o visualizzare il flipper]. Sebbene abbia provato a utilizzare il metodo getWindowManager(), non sono riuscito a ottenere i risultati preferiti.Rompere il testo di grandi dimensioni in pagine nel commutatore di testo Android o visualizzare flipper
Nella seguente discussione si dice che Text Switcher interrompe automaticamente il testo in base alle dimensioni dello schermo. Ma non penso. Managing text in android applicaiton like in a eBook
Questa è la logica che ho usato:
// 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;
int lineCount = 0;
int maxLineCount = screenHeight/contentTextView.getLineHeight();
contentTextView.setLines(maxLineCount);
while ((lineCount < maxLineCount) && (numChars < contentString.length())) {
numChars = numChars + paint.breakText(contentString.substring(numChars), true, screenWidth, null);
lineCount ++;
}
// retrieve the String to be displayed in the current textbox
String toBeDisplayed = contentString.substring(0, numChars);
contentString = contentString.substring(numChars);
contentTextView.setText(toBeDisplayed);
flipper.addView(contentTextView);
numChars = 0;
lineCount = 0;
}
Vedere la mia risposta qui http://stackoverflow.com/questions/20204348/how-to-break-styled-text-into-pages-in-android – mixel