LayoutUtils:
https://www.b4x.com/android/forum/threads/172516/#content
LayoutUtils can be used to create new layout files without using the designer. Use cases that I can think of:
- Conversion of non-B4X layouts.
- Automatic creation of layouts. Something like B4XPreferenceDialog but based on customized layouts.
- Modification of existing layouts. A bit like:
https://www.b4x.com/android/forum/threads/b4x-thememanager-themecreator.172525/#content
How does it work?
Each view is made of various properties. As it is difficult and cumbersome to set all properties manually, we use a "template" layout file. This template holds the views, including custom views, that we then duplicate, modify and use to build a new layout.
For example, to create an AnotherProgressBar from XUI Views:
Dim bar1 As BLView = template.GetView("AnotherProgressBar1").Duplicate("bar1")
bar1.SetHBoth(5, 5) 'no dip units
bar1.SetVBottom(5, 20)
bar1.SetExtra("customProperties.ProgressColor", 0xFF0008C8)
layout.MainView.AddView(bar1)
1. Get the view from the template layout.
2. Duplicate the view and set its new name.
3. Set its horizontal and vertical dimensions.
4. Modify its properties.
5. Add it to an existing panel or main view.
Note that the order of actions isn't strict.
How to find the available properties?
Both BLLayout and BLView have a Describe method that prints all properties.
Log(template.GetView("AnotherProgressBar1").Describe)
Output:
AnotherProgressBar1 (b4a.example.anotherprogressbar)
EventName: AnotherProgressBar1
Variant 0: HAnchor: LEFT - left=20, width=260 | VAnchor: TOP - top=150, height=30
customProperties:
csType: Dbasic.Designer.MetaCustomView+CustomDataGrid
type:
CornerRadius: 10
customType: b4a.example.anotherprogressbar
ProgressColor: 0xFF075DC0
shortType: AnotherProgressBar
Value: 100
customType: b4a.example.anotherprogressbar
drawable:
csType: Dbasic.Designer.Drawable.ColorWithCornersDrawable
type: .drawable.ColorDrawable
borderColor: 0xFF000000
borderWidth: 0
color: 0xFFFFFFFF
cornerRadius: 0
ellipsize: NONE
enabled: true
fontAwesome:
fontsize: 14.0
hAlignment: LEFT
hanchor: 0
height: 100
left: 100
materialIcons:
shortType: AnotherProgressBar
singleLine: false
style: NORMAL
tag:
text:
textColor: 0xFFF0F8FF
top: 100
typeface: DEFAULT
vAlignment: CENTER_VERTICAL
vanchor: 0
width: 100
Ignore the position related properties. These are set with the methods shown above or by setting the VariantValues (start with a single layout variant to keep things simpler).
See attached example - non-ui app that builds the following B4A layout:
Depends on LayoutUtils v0.91+.