diff --git a/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java b/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java index 44ce38ff73d..8d58636efea 100644 --- a/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java +++ b/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java @@ -333,6 +333,12 @@ public void run() { @Nullable private final AccessibilityManager accessibilityManager; + /** @hide */ + @RestrictTo(LIBRARY_GROUP) + protected interface OnMeasureListener { + void onMeasure(View v); + } + /** * Constructor for the transient bottom bar. * @@ -747,6 +753,21 @@ protected SwipeDismissBehavior getNewBehavior() { } final void showView() { + this.view.setOnMeasureListener(new OnMeasureListener() + { + @Override + public void onMeasure(View v) + { + if (view.getAnimationMode() == ANIMATION_MODE_SLIDE && shouldAnimate()) { + int translationYBottom = getTranslationYBottom(); + if (USE_OFFSET_API) { + ViewCompat.offsetTopAndBottom(view, translationYBottom); + } else { + view.setTranslationY(translationYBottom); + } + } + } + }); if (this.view.getParent() == null) { ViewGroup.LayoutParams lp = this.view.getLayoutParams(); @@ -1076,7 +1097,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator animator) { } private int getTranslationYBottom() { - int translationY = view.getHeight(); + int translationY = view.getMeasuredHeight(); LayoutParams layoutParams = view.getLayoutParams(); if (layoutParams instanceof MarginLayoutParams) { translationY += ((MarginLayoutParams) layoutParams).bottomMargin; @@ -1148,6 +1169,7 @@ public boolean onTouch(View v, MotionEvent event) { } }; + private BaseTransientBottomBar.OnMeasureListener onMeasureListener; @Nullable private BaseTransientBottomBar baseTransientBottomBar; @Nullable ShapeAppearanceModel shapeAppearanceModel; @AnimationMode private int animationMode; @@ -1269,6 +1291,13 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { } } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (onMeasureListener != null) + onMeasureListener.onMeasure(this); + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -1300,6 +1329,10 @@ public void setLayoutParams(ViewGroup.LayoutParams params) { } } + void setOnMeasureListener(BaseTransientBottomBar.OnMeasureListener listener) { + onMeasureListener = listener; + } + @AnimationMode int getAnimationMode() { return animationMode;