Fix ScrollView showing unnecessary scrollbars when margins are applied on Android #12
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.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixed an issue where ScrollView on Android devices would incorrectly display scrollbars and enable scrolling behavior when margins were applied to a control containing the ScrollView, even when the content fit within the available space.
Root Cause
The issue occurred because the Android ScrollView was being measured with the original constraints (before accounting for padding/margins), causing it to think it had more space than actually available. When an inset panel is present to handle margins and padding, the ScrollView's measurement logic didn't account for the space that would be consumed by the inset panel.
Solution
Modified the
GetDesiredSize()method inScrollViewHandler.Android.csto:Before/After Behavior
Before: ScrollView with margin would show scrollbars and allow scrolling even when content fits within available space
After: ScrollView with margin only shows scrollbars when content actually exceeds the available space after accounting for margins
Testing
ScrollViewMarginIssue.xamlto reproduce the issueScrollViewMarginIssue.csfor validationThis change restores the correct behavior that was present in Xamarin.Forms and ensures ScrollViews behave predictably when margins are applied.
Fixes #11.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
4vyvsblobprodcus361.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)4zjvsblobprodcus390.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj(dns block)gervsblobprodcus329.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)jd4vsblobprodcus366.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)kxqvsblobprodcus376.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)o3svsblobprodcus318.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)rcxvsblobprodcus328.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)tphvsblobprodcus375.vsblob.vsassets.iodotnet build src/Core/tests/DeviceTests/Core.DeviceTests.csproj(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.