Skip to content

Commit 6d1c490

Browse files
authored
Merge pull request #77 from siralam/master
SimplePagerTitleView now returns correct ContentLeft and ContentRight…
2 parents ec20414 + 5d87f53 commit 6d1c490

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/SimplePagerTitleView.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ public void onEnter(int index, int totalCount, float enterPercent, boolean leftT
5454
@Override
5555
public int getContentLeft() {
5656
Rect bound = new Rect();
57-
getPaint().getTextBounds(getText().toString(), 0, getText().length(), bound);
57+
String longestString = "";
58+
if (getText().toString().contains("\n")) {
59+
String[] brokenStrings = getText().toString().split("\\n");
60+
for (String each : brokenStrings) {
61+
if (each.length() > longestString.length()) longestString = each;
62+
}
63+
} else {
64+
longestString = getText().toString();
65+
}
66+
getPaint().getTextBounds(longestString, 0, longestString.length(), bound);
5867
int contentWidth = bound.width();
5968
return getLeft() + getWidth() / 2 - contentWidth / 2;
6069
}
@@ -69,7 +78,16 @@ public int getContentTop() {
6978
@Override
7079
public int getContentRight() {
7180
Rect bound = new Rect();
72-
getPaint().getTextBounds(getText().toString(), 0, getText().length(), bound);
81+
String longestString = "";
82+
if (getText().toString().contains("\n")) {
83+
String[] brokenStrings = getText().toString().split("\\n");
84+
for (String each : brokenStrings) {
85+
if (each.length() > longestString.length()) longestString = each;
86+
}
87+
} else {
88+
longestString = getText().toString();
89+
}
90+
getPaint().getTextBounds(longestString, 0, longestString.length(), bound);
7391
int contentWidth = bound.width();
7492
return getLeft() + getWidth() / 2 + contentWidth / 2;
7593
}

0 commit comments

Comments
 (0)