Skip to content

Instantly share code, notes, and snippets.

@umetsu
Created January 7, 2015 07:03
Show Gist options
  • Save umetsu/84c5a7b5ea2da7e5dfd2 to your computer and use it in GitHub Desktop.
Save umetsu/84c5a7b5ea2da7e5dfd2 to your computer and use it in GitHub Desktop.
import android.text.TextUtils;
import android.widget.TextView;
/**
* Created by umetsu_kentaro on 2014/09/17.
*/
public final class EllipsizeUtil {
/**
* @param view TextView
* @param maxLines 最大行数
* @param where 省略する箇所
*/
public static CharSequence getEllipsizedText(final TextView view, final int maxLines, final TextUtils.TruncateAt where) {
float avail = 0.0f;
for (int i = 0; i < maxLines; ++i) {
avail += view.getLayout().getLineMax(i);
}
return TextUtils.ellipsize(view.getText(), view.getPaint(), avail, where);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment