[Android] Grid ColumnSpacing affects child's scrollview content size #32381
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.
Issue Details:
When ColumnSpacing is applied to a Grid, and a child ScrollView is set to span multiple columns using Grid.ColumnSpan, the scroll content does not expand to match the full width of the ScrollView. As a result, an unintended empty space appears on the right side of the content.
Root Cause:
During the measure phase, views spanning multiple columns were measured using only the sum of the individual column widths, excluding the spacing between those columns.
However, during the arrange phase, the same views were positioned using bounds that included both column widths and inter-column spacing.
This mismatch led to the visual gap.
Example Scenario:
Measure phase: be measured for 80 units (sum of column widths)
Arrange phase: be laid out over 100 units (columns + spacing)
This discrepancy caused extra visible space on the right.
Description of Change:
The fix ensures consistency between the measure and arrange phases by adjusting the width calculation for multi-column spans.
In GridLayoutManager.cs, the logic was updated to include column spacing during measurement for any view that spans multiple columns. Specifically:
were modified to add (cell.ColumnSpan - 1) * _columnSpacing to the measured width.
This ensures that spanning views are measured using the same total width they will occupy when arranged, eliminating the extra gap and restoring proper layout behavior.
Tested the behavior in the following platforms.
Reference:
N/A
Issues Fixed:
Fixes #24354
Screenshots