Adding more reliable calculation of label width.

This commit is contained in:
opyale
2020-04-12 20:33:41 +02:00
parent df2bc91e9f
commit a7213add30
2 changed files with 19 additions and 1 deletions

View File

@@ -1,11 +1,28 @@
package org.mian.gitnex.helpers;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
/**
* Author M M Arif
*/
public class LabelWidthCalculator {
public static int calculateLabelWidth(String text, Typeface typeface, int textSize, int paddingLeftRight) {
Paint paint = new Paint();
Rect rect = new Rect();
paint.setTextSize(textSize);
paint.setTypeface(typeface);
paint.getTextBounds(text, 0, text.length(), rect);
return rect.width() + (paddingLeftRight * 2);
}
public static int customWidth(int labelLength) {
int width = 33;