Skip to content
Snippets Groups Projects
Commit 9eaa9b24 authored by Olivier St-Onge's avatar Olivier St-Onge Committed by Android (Google) Code Review
Browse files

Merge "Check if PageIndicator's width matches the number of pages." into main

parents 759538ca 9fc8861e
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,10 @@ public class PageIndicator extends ViewGroup {
public void setNumPages(int numPages) {
setVisibility(numPages > 1 ? View.VISIBLE : View.GONE);
if (numPages == getChildCount()) {
int childCount = getChildCount();
// We're checking if the width needs to be updated as it's possible that the number of pages
// was changed while the page indicator was not visible, automatically skipping onMeasure.
if (numPages == childCount && calculateWidth(childCount) == getMeasuredWidth()) {
return;
}
if (mAnimating) {
......@@ -295,6 +298,10 @@ public class PageIndicator extends ViewGroup {
}
}
private int calculateWidth(int numPages) {
return (mPageIndicatorWidth - mPageDotWidth) * (numPages - 1) + mPageDotWidth;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int N = getChildCount();
......@@ -309,7 +316,7 @@ public class PageIndicator extends ViewGroup {
for (int i = 0; i < N; i++) {
getChildAt(i).measure(widthChildSpec, heightChildSpec);
}
int width = (mPageIndicatorWidth - mPageDotWidth) * (N - 1) + mPageDotWidth;
int width = calculateWidth(N);
setMeasuredDimension(width, mPageIndicatorHeight);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment