Created
January 7, 2015 07:03
-
-
Save umetsu/84c5a7b5ea2da7e5dfd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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