Droiuby Layout File Reference
Clone this wiki locally
This section describes how layouts work and an overview of common DroiubyML tags.
The Droiuby Layout File
The Droiuby Layout file is a normal XML file that provides Droiuby instructions on how to build the current android view. Each tag correspond directly to a native android widget object. The XML file is designed so that it will look familiar to web developers. Below is an example of a layout file:
<activity controller="main.rb#main"> <preload id="android_log_drawable" type="image" src="http://upload.wikimedia.org/wikipedia/en/a/a5/Android-logo.jpg"/> <layout type="scroll" width="match" height="match"> <layout type="linear" width="match" background="@preload:android_log_drawable"> <t>Hello World</t> </layout> </layout> </activity>
A droiuby layout file always starts with an activity node. The activity node can optionally have a controller attribute which defines a the location of a ruby script and the name of the activity class to instantiate. That ruby script will be executed after the droiuby activity builder is finished with setting up the android views. Do note however that droiuby will already be doing some preparsing even before the activity builder is finished.
The preload section
The preload elements come after the activity element. Here assets that must be available before the views are instantiated are defined here. This is in contrast to assets that are referenced inside the layout in which the image reference are loaded asynchronously and are not guaranteed to be available even after the activity builder is finished.
<img src="http://upload.wikimedia.org/wikipedia/en/a/a5/Android-logo.jpg" width="100"/>
Use preload only when necessary as it blocks the loading of the "page". References to preload elements are done with the @preload: modifier.
The main layout body
The main layout contains tags that the Activity Builder uses to construct android widgets. Here nodes are evaluated one by one and each corresponding android widget is instantiaed and attached to its parent layout. The activity builder will also process id and class attributes and store them in a hash to be referenced later. Although droiuby accepts strings as ids, android only accepts ids as integers, droiuby will generate a random id and record it for reference later. The V universal selector automatically handles these details by using the activity builder's dictionary or using androids findViewById() for you.