NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/CorrectlyMeasuringTextView....

29 lines
938 B
Java
Raw Normal View History

2017-03-31 01:58:05 +02:00
package org.telegram.ui.Components;
import android.content.Context;
import android.text.Layout;
import android.widget.TextView;
2017-07-08 18:32:04 +02:00
public class CorrectlyMeasuringTextView extends TextView {
2017-03-31 01:58:05 +02:00
public CorrectlyMeasuringTextView(Context context) {
super(context);
}
public void onMeasure(int wms, int hms) {
super.onMeasure(wms, hms);
try {
Layout l = getLayout();
2017-07-08 18:32:04 +02:00
if (l.getLineCount() <= 1) {
return;
}
2017-03-31 01:58:05 +02:00
int maxw = 0;
for (int i = l.getLineCount() - 1; i >= 0; --i) {
maxw = Math.max(maxw, Math.round(l.getPaint().measureText(getText(), l.getLineStart(i), l.getLineEnd(i))));
}
super.onMeasure(Math.min(maxw + getPaddingLeft() + getPaddingRight(), getMeasuredWidth()) | MeasureSpec.EXACTLY, getMeasuredHeight() | MeasureSpec.EXACTLY);
2017-07-08 18:32:04 +02:00
} catch (Exception ignore) {
2017-03-31 01:58:05 +02:00
}
}
}