Fix SurfaceView overflow in RESIZE_MODE_ZOOM#3055
Open
yemirhan wants to merge 1 commit intoandroidx:releasefrom
Open
Fix SurfaceView overflow in RESIZE_MODE_ZOOM#3055yemirhan wants to merge 1 commit intoandroidx:releasefrom
yemirhan wants to merge 1 commit intoandroidx:releasefrom
Conversation
When using RESIZE_MODE_ZOOM, AspectRatioFrameLayout previously expanded its own measured dimensions beyond parent bounds. This caused SurfaceView's separate hardware surface to extend past the frame, making videos overlap neighboring items in RecyclerView/LazyColumn. This fix keeps the frame at parent-provided size while still measuring children at the zoomed (expanded) size: - Save original dimensions in onMeasure and reset via setMeasuredDimension after children are measured at zoomed size - Override onLayout to center oversized children within the frame for a symmetric center-crop effect - Override dispatchDraw to clip the canvas for canvas-drawn children (TextureView, ImageView), which combined with FrameLayout's default clipChildren=true also enables RenderNode clipping for SurfaceView on API 29+ Other resize modes and wrap_content children (buffering spinner, error text) are unaffected as all new logic is guarded by RESIZE_MODE_ZOOM. Fixes: androidx#1107
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SurfaceViewoverflow inAspectRatioFrameLayoutwhen usingRESIZE_MODE_ZOOM, which caused videos to overlap neighboring items inRecyclerView/LazyColumnDetails
When using
RESIZE_MODE_ZOOM,AspectRatioFrameLayoutpreviously expanded its own measured dimensions beyond parent bounds.SurfaceView's separate hardware surface extended past the frame, causing videos to visually overlap neighboring list items.TextureViewwas unaffected since it renders through the normal canvas pipeline.Changes to
AspectRatioFrameLayout.java:onMeasure()— After measuring children at zoomed size, resets the frame's measured dimensions back to the original parent-constrained size viasetMeasuredDimension()onLayout()— Centers children whose measured size exceeds the frame for a symmetric center-crop effect.wrap_contentchildren (buffering spinner, error text) are left untoucheddispatchDraw()— Clips the canvas to the frame's bounds. Combined withFrameLayout's defaultclipChildren=true, this also enables RenderNode-based clipping forSurfaceViewon API 29+Other resize modes (FIT, FILL, FIXED_WIDTH, FIXED_HEIGHT) are unaffected — all new logic is guarded by
resizeMode == RESIZE_MODE_ZOOM.Test plan
PlayerViews (both usingRESIZE_MODE_ZOOM+SurfaceView) stacked vertically with a colored divider — videos no longer bleed past their boundsFixes #1107