Skip to content

Commit df8a325

Browse files
committed
[Carousel] Update mask size when MaskableFrameLayout size is changed
1 parent 7822ef8 commit df8a325

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/java/com/google/android/material/carousel/MaskableFrameLayout.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public MaskableFrameLayout(
6565
@Override
6666
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
6767
super.onSizeChanged(w, h, oldw, oldh);
68-
onMaskChanged();
68+
updateMaskRect();
6969
}
7070

7171
@Override
@@ -123,13 +123,17 @@ public void setMaskXPercentage(float percentage) {
123123
percentage = MathUtils.clamp(percentage, 0F, 1F);
124124
if (maskXPercentage != percentage) {
125125
this.maskXPercentage = percentage;
126-
// Translate the percentage into an actual pixel value of how much of this view should be
127-
// masked away.
128-
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
129-
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
126+
updateMaskRect();
130127
}
131128
}
132129

130+
private void updateMaskRect() {
131+
// Translate the percentage into an actual pixel value of how much of this view should be
132+
// masked away.
133+
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
134+
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
135+
}
136+
133137
/**
134138
* Sets the {@link RectF} that this {@link View} will be masked by.
135139
*

0 commit comments

Comments
 (0)