Wish Is there a reason why a Panel cannot have Gravity?

Widget

Well-Known Member
Licensed User
Longtime User
Why can't a Panel have a Gravity property? (Delphi has an Align property that makes positioning panels a breeze when the window resizes.)

This comes in handy when you need to position a panel relative to its parent panel (or Activity).

Example. If you want a panel to be at the bottom of another panel (or activity) you would use "Panel1.Gravity = Bottom". When the parent panel resizes, Panel1 will be repositioned so its bottom is always aligned to the bottom of the parent.

This will allow us to use code to simulate the Designer's panel anchors & more! We will be able to position sections of the screen much easier using code.

Examples:

B4X:
Panel1.Gravity = Bottom                          'Align Panel1 to bottom of parent panel
Panel1.Gravity = Bottom + Left + Right    'Align Panel1 so it fills bottom of parent panel (its height will not change)
Panel1.Gravity = Center                           'Align Panel1 to vertical & horizontal center of parent panel
Panel1.Gravity = Fill                                 'Align Panel1 so it fills its parent panel
Panel1.Gravity = TOP + BOTTOM + RIGHT  'Align Panel1 to right edge and height of parent (its width will not change)
Panel1.Gravity = Center_Horizontal   'Align Panel1 so it is centered horizontally within its parent
Panel1.Gravity = Center_Vertical       'Align Panel1 so it is centered vertically within its parent

If the parent panel has more than one panel with Gravity=Right, then the panels will align with each other (to prevent the panels from stacking on top of each other).

So when a Panel (or activity) is resized, the panels that it contains will be realigned automatically.


Also a Panel.Border (Rect) property would be welcomed because then we could define a gap between the Panel and what it is aligned to.

B4X:
'Align the panel to the right with a 5dip gap from the right edge of the activity (or parent panel)
Panel1.Border.Top = 10dip   'Larger gap at the top
Panel1.Border.Right = 5dip   'Narrower gap at the right
Panel1.Gravity = Right


What do you think?
 

Widget

Well-Known Member
Licensed User
Longtime User
I thought it was a good idea to give Panel a Gravity property so it can be controlled using code. But it got no replies. I'm feeling like Rodney Dangerfield here. :oops:
Did I miss something? Was it a bad idea? Or has it already been implemented another way using code?
 
Top