String 두줄까지만 출력하고 마지막에 ... 처리
private void applyNewLineCharacter(TextView textView) { Paint paint = textView.getPaint(); String text = (String) textView.getText(); int frameWidth = mCtx.getResources().getDimensionPixelOffset(R.dimen.description_width); int startIndex = 0; int endIndex = paint.breakText(text , true, frameWidth, null); String save = text.substring(startIndex, endIndex); int lines = 1;
while(true) { startIndex = endIndex; text = text.substring(startIndex);
if(text.length() == 0) break; else lines++;
if(lines == 3) { save = save.substring(0, save.length() - 2) + "..."; break; } endIndex = paint.breakText(text, true, frameWidth, null); save += "\n" + text.substring(0, endIndex); } textView.setText(save); } |