I've been working on implementing native Padding and Margin properties
for visible components as requested in issue #4019. I'd love feedback
before opening a PR.
What this does
Adds Padding and Margin properties to AndroidViewComponent subclasses
where they have clear visual semantics. Values are comma-separated strings
in Top,Left,Right,Bottom format (e.g. "8,8,8,8").
Designer
A new cross-shaped 4-textbox property editor handles both properties:
Margin is correctly accounted for in the Designer canvas layout,
components don't overlap when margin is set, because I hooked the
margin/padding values into LayoutInfo.getLayoutWidth/Height() so
MockHVLayoutBase reserves the correct space when positioning siblings.
Blocks
Supports both String and YailList
Padding/Margin Distribution Rules (Applies to both String and YailList):
- 1 Value: Apply this single value to all 4 sides (e.g.,
"4"or[4]becomes4, 4, 4, 4). - 2 Values: Keep the first 2 values; fill the remaining 2 sides with
0(e.g.,"2,4"becomes2, 4, 0, 0). - 3 Values: Keep the first 3 values; fill the last side with
0(e.g.,"2,4,5"becomes2, 4, 5, 0). - 4 Values: Behave exactly like the original logic.
Runtime
Scope
Included:
Button, Label, TextBox, EmailPicker, PasswordTextBox, CheckBox, Switch,
Image, HorizontalArrangement, VerticalArrangement,
HorizontalScrollArrangement, VerticalScrollArrangement, TableArrangement,
AbsoluteArrangement, ListView, Spinner, DatePicker, TimePicker,
ContactPicker, ImagePicker, ListPicker, PhoneNumberPicker, FilePicker
Excluded via override suppression:
- Canvas — would break sprite coordinate assumptions
- VideoPlayer, WebViewer — have their own internal padding concepts
- Map, FeatureCollection — map rendering semantics don't fit box model
- Chart, CircularProgress, LinearProgress, Slider — padding has no
clear visual meaning for these widget types
Implementation notes
- Property defined once in AndroidViewComponent, inherited by all
in-scope components - ButtonBase overrides updateAppearance() and setHighContrast() to
re-assert padding after background drawable reassignment (a known
Android behavior that resets view padding when a new drawable is set) - All affected component versions bumped, upgrade paths added in
YoungAndroidFormUpgrader, noUpgrade entries added in versioning.js - All 140 existing tests pass
Happy to discuss scope decisions or any implementation details.
Reference: Native Padding and Margin layout controls for UI components · Issue #4019 · mit-cml/appinventor-sources · GitHub



