Skip to content

Commit 9474070

Browse files
author
marunjar
committed
dynamic time column width
1 parent 818c559 commit 9474070

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,17 @@ public boolean onScale(ScaleGestureDetector detector) {
400400
}
401401

402402
/**
403-
* Initialize time column width. Calculate value with latest possible hour (supposed widest text)
403+
* Initialize time column width. Calculate value with all possible hours (supposed widest text)
404404
*/
405405
private void initTextTimeWidth() {
406-
String timeSample = getDateTimeInterpreter().interpretTime(23);
407-
mTimeTextWidth = mTimeTextPaint.measureText(timeSample);
406+
mTimeTextWidth = 0;
407+
for (int i = 0; i < 24; i++) {
408+
// measure time string and get max width
409+
String time = getDateTimeInterpreter().interpretTime(i);
410+
if (time == null)
411+
throw new IllegalStateException("A DateTimeInterpreter must not return null time");
412+
mTimeTextWidth = Math.max(mTimeTextWidth, mTimeTextPaint.measureText(time));
413+
}
408414
}
409415

410416
@Override

0 commit comments

Comments
 (0)