Skip to content

Instantly share code, notes, and snippets.

@dron247
Created April 5, 2017 03:59
Show Gist options
  • Save dron247/e517cc9dbd9a9865ec41658bad18b5ab to your computer and use it in GitHub Desktop.
Save dron247/e517cc9dbd9a9865ec41658bad18b5ab to your computer and use it in GitHub Desktop.
This code for ViewHolder helps you to shorten your text lines which do not fit into your list item. Smooth scroll as a result.
int maxWidth = viewHolder.viewGroup.getWidth();
TextPaint textPaint = viewHolder.titleView.getPaint();
String title = cursor.getString(ArticlesQuery.TITLE);
int chars = textPaint.breakText(title, true, maxWidth, null);
if (chars < title.length()) {
title = title.substring(0, chars);
}
viewHolder.titleView.setText(title);
// source: http://martinadamek.com/2011/01/04/performance-of-android-listview-containing-textviews/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment