StackLayout manages several views stacked into the same space. It has two modes: it can either switch the view that is visible, hiding the others, or it can keep all of them visible, switching the one that is on top.
The second mode is useful for example for overlaying a view with a UserView, on which you can then draw additional information. If you still want to be able to interact with the view below using the mouse, you can make the one above ignore the mouse using View: -acceptsMouse. See the example below.
Views can be added to the layout immediately at construction, or you can add or insert them after. To remove a view, you simply call View: -remove.
You can change the current view (the one visible / on top) using -index, while -count tells you how many views are managed by the layout.
To switch between the two modes use -mode.
Creates a StackLayout and fills it with the items given as arguments. The first view becomes the current one, i.e. visible and on top of others.
... views |
A sequence of views. Unlike other layouts, StackLayout can not contain another layout. |
In the example below, the button will switch between the three text editing areas:
Inserts a view at the specific index. This does not affect the current -index.
view |
A View. |
index |
An integer. If it is less than 0 or more than -count, the view will always be inserted as last. |
The number of views managed by the layout.
Sets or gets the index of the current view. The current view is placed on top of others, and if -mode is 0, all the others are hidden.
Sets or gets the current mode: in mode 0, the layout only displays the current view; in mode 1, the layout displays all the views. In both modes, the current view will be placed on top of others.
See also: -index.
value |
0 or 1. Instead of an integer you can also use symbols \stackOne or \stackAll. |
0 or 1.
Overlaying a TextView with a UserView to do additional drawing on top, while still allowing the interaction with the text: