Designing User Interfaces with Layouts Chapter 9 User

  • Slides: 15
Download presentation
Designing User Interfaces with Layouts Chapter 9

Designing User Interfaces with Layouts Chapter 9

User Interfaces • The term layout is used for two different purposed in Android

User Interfaces • The term layout is used for two different purposed in Android user interface design: • The /res/layout directory contains XML resource definitions often called layout resource files • Term is used to refer to a set of View. Group classes that include: • • • Linear. Layout Frame. Layout Table. Layout Relative. Layout Grid. Layout These controls are used to organize other View controls

User Interfaces • Android provides a simple way to create layout resources files in

User Interfaces • Android provides a simple way to create layout resources files in XML • This is the most common and convenient way to build Android user interfaces • You can configure almost any View. Group or View attribute using the XML layout resource files • This method simplifies the user interface design process • A layout is associated with an Activity which sets the main. xml layout by default set. Content. View(R. layout. main);

User Interfaces • You can create user interface components such as layouts at runtime

User Interfaces • You can create user interface components such as layouts at runtime programmatically • Recommend that you leave this for the odd case rather than the norm • Creation of layouts programmatically is difficult to maintain compared to the XML resource which are visual and more organized

User Interfaces • The class View is the building block for user interfaces •

User Interfaces • The class View is the building block for user interfaces • All user interface controls such as Button, Spinner, and Edit. Text are derived from the View class • View. Group is a special kind of View • Classes derived from View. Group enable developers to display View controls such as Text. View and Button control in an organized fashion • View. Group represent a rectangle of screen space • May contain other View controls • View that contains other View controls is called a parent view • The parent View contains View controls called child views

User Interfaces • View. Group subclasses are broken down into two categories: • Layout

User Interfaces • View. Group subclasses are broken down into two categories: • Layout classes • View container controls – provide a kind of active functionality that enables users to interact with them like other controls • Named for the kind of functionality they provide • Gallery – is a horizontal scrolling list of View controls with a center “current” item; user can browse the View controls by scrolling left and right • Grid. View • Image. Switcher • Scroll. View • Tab. Host – complex View container; each tab can contain a View; user selects a tab to see its contents • List. View – displays each View control as a list item

Built-in Layout Classes • • Layouts are derived from android. View. Group All layouts

Built-in Layout Classes • • Layouts are derived from android. View. Group All layouts have basic layout attributes Attributes apply to any child View control within the layout Several layout attributes are shared: • Size attributes • Margin attributes

Built-in Layout Classes • Frame. Layout • Designed to display a stack of child

Built-in Layout Classes • Frame. Layout • Designed to display a stack of child View items • Attributes for Frame. Layout child View controls can be found in android. widget. Frame. Layout. Params • Example Frame. Layout • • Frame. Layout with 2 child View controls Green rectangle is drawn first Red oval is drawn on top of it Green rectangle is large so it defines the bounds of the Frame. Layout

Built-in Layout Classes • Linear. Layout • Organizes its child View controls in a

Built-in Layout Classes • Linear. Layout • Organizes its child View controls in a single row or a single column depending on the orientation attribute, horizontal or vertical • Good layout method for creating forms

Built-in Layout Classes • Relative. Layout • Specify where the child view controls are

Built-in Layout Classes • Relative. Layout • Specify where the child view controls are in relation to each other • Can set a child View to be positioned above or below or to the left or to the right referred to by a unique identifier • Can align child View controls relative to one another or the parent layout edges

Built-in Layout Classes • Table. Layout • Organizes children into rows • Organize individual

Built-in Layout Classes • Table. Layout • Organizes children into rows • Organize individual control within each row using a Table. Row layout View • Place items in the Table. Row in columns in the order they are added • Specify column numbers (zero based) otherwise control is put in the next column to the right • Columns scale to the size of the largest View of that column

Built-in Layout Classes • Grid. Layout • • Organizes children inside a grid Layout

Built-in Layout Classes • Grid. Layout • • Organizes children inside a grid Layout grid is dynamically created Child control can span rows and columns Introduced in Android 4. 0 (API Level 14)

Container Control Classes • Containers • Give the user the ability to interactively browse

Container Control Classes • Containers • Give the user the ability to interactively browse the child View controls • View. Group containers built in to the Android SDK framework include: • • • Lists, grids, and galleries Tabs with Tab. Host and Tab. Control scroll. View and Horizontal. Scroll. View for scrolling View. Flipper, Image. Switcher, and Text. Switcher for switching Sliding. Drawer for hiding and showing content

Container Control Classes • Containers designed to display repetitive View controls in a particular

Container Control Classes • Containers designed to display repetitive View controls in a particular way • List. View – contains a vertically scrolling, horizontally filled list which typically contains a row of data; user can choose an item to perform some action upon. • Grid. View – contains a grid with a specific number of columns; often used with image icons; user can choose an item to perform some action upon. • Gallery. View – contains a horizontally scrolling list that is often used with image icons; user can select an item to perform some action upon.

Container Control Classes • These containers are all types of Adapter. View controls. •

Container Control Classes • These containers are all types of Adapter. View controls. • An Adapter. View control is built with child View controls to display data from a data source. • You need to bind data to View controls using Adapter object. • Adapter reads data from source and generates data from a View control based on rules associated with type of Adapter. • Most common Adapter classes: • Cursor. Adapter – used with database • Array. Adapter – used with array