/** * Optimization for when you have TextViews that truncate, per http://www.martinadamek * .com/2011/01/05/performance-of-android-listview-containing-textviews/ * * @param str * @param textView * @return */ public static CharSequence ellipsizeString(CharSequence str, TextView textView) { int width = textView.getWidth() - textView.getCompoundPaddingLeft() - textView.getCompoundPaddingRight(); return ellipsizeString(str, width, textView.getPaint()); }
private static float convertToLocalHorizontalCoordinate(float x, TextView tv) { if (tv.getLayout() == null) { x -= tv.getCompoundPaddingLeft(); } else { x -= tv.getTotalPaddingLeft(); } // Clamp the position to inside of the view. x = Math.max(0.0f, x); float rightSide = tv.getWidth() - 1; if (tv.getLayout() == null) { rightSide -= tv.getCompoundPaddingRight(); } else { rightSide -= tv.getTotalPaddingRight(); } x = Math.min(rightSide, x); x += tv.getScrollX(); return x; }