diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 488e666087..33321f3dfb 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -18,6 +18,9 @@ * Add group setting to `PlayerNotificationManager`. * Fix `StyledPlayerView` scrubber not reappearing correctly in some cases ([#8646](https://github.com/google/ExoPlayer/issues/8646)). + * Fix measurement of `StyledPlayerView` and `StyledPlayerControlView` + when `wrap_content` is used + ([#8726](https://github.com/google/ExoPlayer/issues/8726)). * Audio: * Report unexpected discontinuities in `AnalyticsListener.onAudioSinkError` diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index 2c35ee5c2b..c2e7446e8a 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -1582,29 +1582,6 @@ public class StyledPlayerControlView extends FrameLayout { } } - private void onLayoutChange( - View v, - int left, - int top, - int right, - int bottom, - int oldLeft, - int oldTop, - int oldRight, - int oldBottom) { - int width = right - left; - int height = bottom - top; - int oldWidth = oldRight - oldLeft; - int oldHeight = oldBottom - oldTop; - - if ((width != oldWidth || height != oldHeight) && settingsWindow.isShowing()) { - updateSettingsWindowSize(); - int xOffset = getWidth() - settingsWindow.getWidth() - settingsWindowMargin; - int yOffset = -settingsWindow.getHeight() - settingsWindowMargin; - settingsWindow.update(v, xOffset, yOffset, -1, -1); - } - } - @Override public void onAttachedToWindow() { super.onAttachedToWindow(); @@ -1676,6 +1653,35 @@ public class StyledPlayerControlView extends FrameLayout { return true; } + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + controlViewLayoutManager.onLayout(changed, left, top, right, bottom); + } + + private void onLayoutChange( + View v, + int left, + int top, + int right, + int bottom, + int oldLeft, + int oldTop, + int oldRight, + int oldBottom) { + int width = right - left; + int height = bottom - top; + int oldWidth = oldRight - oldLeft; + int oldHeight = oldBottom - oldTop; + + if ((width != oldWidth || height != oldHeight) && settingsWindow.isShowing()) { + updateSettingsWindowSize(); + int xOffset = getWidth() - settingsWindow.getWidth() - settingsWindowMargin; + int yOffset = -settingsWindow.getHeight() - settingsWindowMargin; + settingsWindow.update(v, xOffset, yOffset, -1, -1); + } + } + private boolean shouldShowPauseButton() { return player != null && player.getPlaybackState() != Player.STATE_ENDED diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlViewLayoutManager.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlViewLayoutManager.java index 3b901fc6ea..00599314ec 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlViewLayoutManager.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlViewLayoutManager.java @@ -50,6 +50,7 @@ import java.util.List; private final StyledPlayerControlView styledPlayerControlView; + @Nullable private final View controlsBackground; @Nullable private final ViewGroup centerControls; @Nullable private final ViewGroup bottomBar; @Nullable private final ViewGroup minimalControls; @@ -99,7 +100,7 @@ import java.util.List; shownButtons = new ArrayList<>(); // Relating to Center View - View controlsBackground = styledPlayerControlView.findViewById(R.id.exo_controls_background); + controlsBackground = styledPlayerControlView.findViewById(R.id.exo_controls_background); centerControls = styledPlayerControlView.findViewById(R.id.exo_center_controls); // Relating to Minimal Layout @@ -464,6 +465,15 @@ import java.util.List; } } + public void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (controlsBackground != null) { + // The background view should occupy the entirety of the parent. This is done in code rather + // than in layout XML to stop the background view from influencing the size of the parent if + // it uses "wrap_content". See: https://github.com/google/ExoPlayer/issues/8726. + controlsBackground.layout(0, 0, right - left, bottom - top); + } + } + private void onLayoutChange( View v, int left, diff --git a/library/ui/src/main/res/layout/exo_styled_player_control_view.xml b/library/ui/src/main/res/layout/exo_styled_player_control_view.xml index d50ff9908c..5c8153bf17 100644 --- a/library/ui/src/main/res/layout/exo_styled_player_control_view.xml +++ b/library/ui/src/main/res/layout/exo_styled_player_control_view.xml @@ -15,10 +15,14 @@ --> +