Skip to content
Ashish Bahl edited this page Aug 3, 2022 · 3 revisions

A LayoutBuilder is used to build all the Views in Proteus. To get an instance of a LayoutBuilder create a new instance of LayoutBuilderFactory. The factory returns singleton instances of different types LayoutBuilders.

LayoutBuilderFactory layoutBuilderFactory = new LayoutBuilderFactory();

There are 3 types of builders:

  • SimpleLayoutBuilder
  • DataParsingLayoutBuilder
  • DataAndViewParsingLayoutBuilder
LayoutBuilder builder;

builder = layoutBuilderFactory.getSimpleLayoutBuilder();

builder = layoutBuilderFactory.getDataParsingLayoutBuilder();

builder = layoutBuilderFactory.getDataAndViewParsingLayoutBuilder(Map<String, JsonObject> viewProvider);

Building Views

ProteusView view = builder.build(parent, layout, data, styles -1);
  • parent The parent view whose LayoutParams the ProteusView will inherit.
  • layout The JsonObject layout for the View.
  • data The JsonObject data for Data Bindings. (null for SimpleLayoutBuilder)
  • index The Data Index of the view. (-1 for none).

Sample Layout

{
  "type": "LinearLayout",
  "layout_width": "match_parent",
  "layout_height": "wrap_content",
  "background": "#ffffff",
  "orientation": "vertical",
  "padding": "16dp",
  "children": [
    {
      "type": "TextView",
      "layout_width": "wrap_content",
      "layout_height": "wrap_content",
      "layout": "Hello World",
      "textColor": "#444444"
    }
  ]
}

Sample Data

{
  "profile": {
    "name" : "John Doe",
    "level" : "9",
    "credits" : 24031
  }
}

Next: Layouts