Widgets can be divided in two groups:
- 1. Android widgets
- all native Android widgets (under heading “Classes”). Widgets are provided by Android system.
- 2. ginstr widgets
- custom made widgets. They can be composite widgets that consist of multiple Android views or a single view with special functionality.
Widgets can be divided by nesting:
- 1. Container widgets (ViewGroups)
- those widgets are used as containers for other widgets. The purpose is positioning assistance and layout organization. The most important are:
ScrollView(can have one child),
FrameLayout. More are mentioned here.
- 2. Action widgets
- widgets that can’t nest or contain widgets within them. These widgets are used for providing functionality to app (i.e. input text, display text, call phone, send text message…), some of those are (
Widget Library contains all custom ginstr widgets that contain features not provided out of the box by Android.
Attributes define how each widget behaves and what it looks like. Android widgets have attributes described for each widget, for example
EditText (look under XML attributes and Inherited XML attributes). Each attribute has a description what its function is. This is provided for all Android widgets in Android Documentation.
- Example Android widget with attributes:
To use ginstr namespace attributes user has to define custom namespace in top (root) element (widget) of the layout.
xmlns:ek=http://schemas.ginstr.com/ginstr. To define custom attribute following syntax is used,
- Example of a ginstr widget with attributes:
!IMPORTANT! Each widget has to have
android:layout_height defined. Custom widgets need custom ginstr attribute defined to work properly, check layout configuration of each widget. An attribute marked with asterisk (
*) is a mandatory parameter when creating widget.
One of the most important things is how to handle widget positioning within container widgets. Positioning depends on each widget within a container which depends on the container which contains it. If a widget is contained for example in
LinearLayout it will not have the same positioning options as in
- Example: Widget in
RelativeLayouthas the ability to position itself relative to other views by attribute (example under positions widget containing this attribute to right of widget with id mentioned in attribute)
- Example: Widget in
Practice is needed to learn those few containers and their abilities. With combinations of containers any positioning can be achieved.
Widget data persistence
!IMPORTANT! To enable widgets that retrieve data from a user to retain data between orientation changes a unique id for widget within that layout has to be provided. Id has to be identical in both layouts (landscape/portrait). It is encouraged to use portrait only layout due to better visibility on phone Android devices.