Paint paint = new Paint(); paint.setTextSize(25); float textWidth = paint.measureText("Hello, World!");
Paint paint = new Paint(); paint.setTextSize(20); ListIn this example, we create a new Paint object and set the text size to 20. We then loop through the list of strings, calculate the width of each string using measureText(), and keep track of the maximum width using the Math.max() method. Package Library: android.graphicsstringList = ...; // list of strings float maxWidth = 0; for (String s : stringList) { float textWidth = paint.measureText(s); maxWidth = Math.max(maxWidth, textWidth); }