RelativeLayout and GridLayout allow for flexible layout design in Android applications. RelativeLayout positions elements relative to each other and the parent container using properties like alignParentTop, below, and toRightOf. GridLayout divides space into rows and columns, allowing elements to span multiple cells. It provides solutions for alignment issues in nested layouts and improves performance over deeply nested designs.
CREATING A DATASET FROM EXCEL IN POWER BI REPORT BUILDERSagarDuttPhuloria
This document provides steps to create a dataset from Excel in Power BI Report Builder by:
1. Setting up an embedded data source and dataset in the report using data entered directly.
2. Designing a simple table report based on the created dataset to display aggregated sales data by country and year.
3. Running the report to preview it with actual values and formatting the output.
This document provides an overview of an advanced Microsoft Excel lesson. The objectives are to familiarize students with commonly used Excel functions, conditional functions, and how to use Excel for market research and product development. An example is provided on using Excel to estimate the product cost of a milk tea. Formulas like SUM, subtraction, and division are used to calculate the ingredient costs and determine if the estimated sale price would be profitable. The lesson concludes with a discussion on analyzing survey data in Excel.
This document provides instructions for creating a spreadsheet to track ingredient costs and recipes. It includes:
1) Entering ingredient names, quantities, units, and costs to calculate the cost per gram of each. Formulas are used to automatically fill costs down the list.
2) Creating recipes that list ingredients and amounts, then linking to the cost sheet to calculate total recipe costs.
3) Building a user input sheet with drop-down menus and validation to allow creating new recipes. Formulas look up ingredient costs and calculate totals.
Conditional formatting highlights profits/losses, and sheets can be protected to control user inputs. The full instructions provide a guided tutorial to build this interactive cost and recipe tracking spreadsheet.
Welcome to my series of articles on Unified Modeling Language. This is "Session 11 – Communication Diagram" of the series. Please view my other documents where I have covered each UML diagram with examples
This document discusses the Excel add-in for data mining. It allows users to mine data with a few clicks using advanced algorithms without needing experience in data mining or SQL server configuration. The add-in contains sections for data preparation, modeling, accuracy validation, and connection. Data can be explored, cleaned, and prepared for modeling. Common modeling algorithms like decision trees, clustering, and association rules are available. Accuracy and validation tools allow testing models on real data. The add-in combines the power of SQL Server Analysis Services with the ease of use of Excel.
The Excel TEXT function converts numeric values to text strings in a specified format. It has two required arguments: the value to convert and the format text. The format text uses code like "0" or "dd-mm-yyyy" to determine how numbers or dates should be displayed as text. Some examples show using TEXT to format numbers with commas and currency symbols, concatenate text with formatted dates, and conditionally format values based on location. The TEXT function allows numbers to be displayed in readable formats and combined with text for reports.
This presentation is developed to impart understanding of Microsoft Excel's one of the most unique and powerful function DATEDIF. Which helps in calculating difference between dates.
Merge vs sql join vs append (horizontal vs vertical) bestAraz Abbas Zadeh
This document discusses methods for joining SAS data sets, including vertical and horizontal joins. Vertical joins involve appending one data set to another, while horizontal joins use key variables to combine observations. Specific join methods like inner, left, right, and full joins are explained. The document provides examples demonstrating how to perform each type of join in SAS using PROC SQL and PROC DATASETS. Limitations and potential issues with joining data sets are also addressed.
CREATING A DATASET FROM EXCEL IN POWER BI REPORT BUILDERSagarDuttPhuloria
This document provides steps to create a dataset from Excel in Power BI Report Builder by:
1. Setting up an embedded data source and dataset in the report using data entered directly.
2. Designing a simple table report based on the created dataset to display aggregated sales data by country and year.
3. Running the report to preview it with actual values and formatting the output.
This document provides an overview of an advanced Microsoft Excel lesson. The objectives are to familiarize students with commonly used Excel functions, conditional functions, and how to use Excel for market research and product development. An example is provided on using Excel to estimate the product cost of a milk tea. Formulas like SUM, subtraction, and division are used to calculate the ingredient costs and determine if the estimated sale price would be profitable. The lesson concludes with a discussion on analyzing survey data in Excel.
This document provides instructions for creating a spreadsheet to track ingredient costs and recipes. It includes:
1) Entering ingredient names, quantities, units, and costs to calculate the cost per gram of each. Formulas are used to automatically fill costs down the list.
2) Creating recipes that list ingredients and amounts, then linking to the cost sheet to calculate total recipe costs.
3) Building a user input sheet with drop-down menus and validation to allow creating new recipes. Formulas look up ingredient costs and calculate totals.
Conditional formatting highlights profits/losses, and sheets can be protected to control user inputs. The full instructions provide a guided tutorial to build this interactive cost and recipe tracking spreadsheet.
Welcome to my series of articles on Unified Modeling Language. This is "Session 11 – Communication Diagram" of the series. Please view my other documents where I have covered each UML diagram with examples
This document discusses the Excel add-in for data mining. It allows users to mine data with a few clicks using advanced algorithms without needing experience in data mining or SQL server configuration. The add-in contains sections for data preparation, modeling, accuracy validation, and connection. Data can be explored, cleaned, and prepared for modeling. Common modeling algorithms like decision trees, clustering, and association rules are available. Accuracy and validation tools allow testing models on real data. The add-in combines the power of SQL Server Analysis Services with the ease of use of Excel.
The Excel TEXT function converts numeric values to text strings in a specified format. It has two required arguments: the value to convert and the format text. The format text uses code like "0" or "dd-mm-yyyy" to determine how numbers or dates should be displayed as text. Some examples show using TEXT to format numbers with commas and currency symbols, concatenate text with formatted dates, and conditionally format values based on location. The TEXT function allows numbers to be displayed in readable formats and combined with text for reports.
This presentation is developed to impart understanding of Microsoft Excel's one of the most unique and powerful function DATEDIF. Which helps in calculating difference between dates.
Merge vs sql join vs append (horizontal vs vertical) bestAraz Abbas Zadeh
This document discusses methods for joining SAS data sets, including vertical and horizontal joins. Vertical joins involve appending one data set to another, while horizontal joins use key variables to combine observations. Specific join methods like inner, left, right, and full joins are explained. The document provides examples demonstrating how to perform each type of join in SAS using PROC SQL and PROC DATASETS. Limitations and potential issues with joining data sets are also addressed.
The document discusses Android layouts. It explains that Views are UI components like buttons and text views, and ViewGroups are containers that position Views. The main ViewGroups covered are LinearLayout, which positions Views vertically or horizontally, and RelativeLayout, which positions Views relative to each other or the parent container. Attributes like orientation, gravity, weight and margins are used to control View positioning.
The document outlines the requirements and topics to be covered in an Android training, including developing layouts using XML and Java, running and debugging Android applications, using intents and bundles to pass data between activities, and handling basic data storage using SQLite and memory management. It also provides references and questions for trainees to refer to for more information on Android development concepts and best practices.
The document discusses different types of views and view groups in Android user interface development. It describes layouts like LinearLayout, RelativeLayout and FrameLayout that extend the ViewGroup class. These layouts allow arranging views in different orientations using attributes like layout_width, layout_height, layout_weight etc. The document also talks about defining views and layouts in XML files or programmatically at runtime.
This document discusses Android layouts and UI components. It covers the View and ViewGroup classes, which represent basic UI building blocks. It then covers various layout types like LinearLayout, FrameLayout, RelativeLayout, TableLayout and GridLayout. For each layout, it provides an overview and examples of key XML attributes used to control the layout. It concludes by providing links to sample code and slides for further reference.
The document discusses various techniques for developing efficient Android user interfaces (UIs), including using adapters, view holders, pre-scaling bitmaps, custom views, custom layouts, and more. Adapters act as a bridge between data and views. View holders minimize finding views repeatedly. Pre-scaling bitmaps improves performance over scaling at runtime. Custom views and layouts allow defining user-defined UI elements instead of using pre-defined ones only.
The document discusses various techniques for developing efficient Android user interfaces (UIs), including using adapters, view holders, pre-scaling bitmaps, custom views, custom layouts, and more. Adapters act as a bridge between data and views. View holders minimize finding views repeatedly. Pre-scaling bitmaps improves performance over scaling at runtime. Custom views and layouts allow defining user-defined UI elements.
This post will walk you through Android ListView Tutorial for building simple and customized ListView using different Android adapters.
List is one of the most common UI patterns, which is being used extensively to display the collection of data elements in rows. In android ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array.
This document provides an overview of layouts and user interface design in Android. It discusses the basic building blocks of Android UIs which are Views and ViewGroups. It describes common layout types like LinearLayout, RelativeLayout and TableLayout that can be used to position Views. It also covers attributes like id, width/height, padding etc. that can customize View properties. The document demonstrates how to declare layouts in XML and set View attributes. It emphasizes keeping layout hierarchies shallow to optimize performance.
The document discusses various layout containers used in Android user interface design, including LinearLayout, RelativeLayout, and TableLayout. LinearLayout arranges widgets linearly in a vertical or horizontal orientation. Key properties for LinearLayout include orientation, weight, gravity, padding, and margin. RelativeLayout positions widgets relative to each other and the parent container using positional rules. TableLayout arranges widgets in a grid with rows and columns, where each row is defined by a TableRow container. The document provides examples and details on how to implement each type of layout.
This document discusses implementing a simple network data browsing app in Android. It covers using a ListView to display data retrieved from a network request using Volley, and connecting the ListView to data with a custom adapter. The implementation steps include importing necessary libraries, creating layouts, initializing Volley, generating UI elements, registering button click listeners, making network requests, and viewing results. Additional topics include tools like Postman and JSON parsers, basic Android components, views, view groups, listeners, ListView, intents, and sample code.
This document discusses ListViews and ListActivities in Android application development. It covers:
- ListViews display scrollable lists via an Adapter that provides data and converts it to list fields. Standard adapters include ArrayAdapter and CursorAdapter.
- ListActivities simplify handling lists by extending the Activity class and providing list management methods like setListAdapter() and onListItemClick().
- Adapters can use default or custom layouts and the ListView recycles views for performance. Interacting with the underlying data model is also demonstrated.
The document discusses various aspects of using the GridView control in ASP.NET such as binding data to the GridView, handling paging, sorting and editing. It describes properties like AllowPaging and events like PageIndexChanging. It provides code examples for binding data, handling sorting and paging. The document also discusses different field types that can be used in a GridView like BoundField, TemplateField and HyperLinkField.
This document provides an overview of using DroidDraw, a user interface designer for Android applications. It discusses how DroidDraw allows dragging and dropping widgets onto a screen layout to build a UI visually. Key aspects covered include choosing root layouts like LinearLayout, setting screen size, generating XML code from the designed UI, and exploring different tabs for layouts, properties, strings, and more. The document also provides a brief introduction to key concepts in Android like activities, services, content providers and resources.
The document discusses different layouts in Android, including ConstraintLayout and LinearLayout. ConstraintLayout allows flexible screen layout by defining constraints between views. Views can be constrained to the parent layout or other views. LinearLayout displays views in a single column or row, and options like weight, orientation, and dimensions control how views are distributed. The challenge is to create a calculator screen layout using these techniques.
UI layouts define the structure and organization of elements in an Android activity's user interface. There are two main options for declaring layouts: in XML files or programmatically in Java code. Common layout types include LinearLayout, RelativeLayout, TableLayout, and FrameLayout. Layout files use a tree structure with attributes like ID, width, height, and weight to position child views. This allows separation of UI design from activity code.
1) The document describes building a simple user interface with an XML layout containing an EditText field and a Button. It explains how to define the UI elements in XML and add string resources for the text labels.
2) Key steps include creating a LinearLayout, adding an EditText and Button, setting attributes like IDs and dimensions, and externalizing strings to a resources file for localization.
3) Running the app displays the basic UI layout with an input field and button as defined in the XML code.
While it is technically possible to create and attach widgets to your activity purely through Java code, the more common approach is to use an XML-based layout file. Dynamic instantiation of widgets is reserved for more complicated scenarios, where the widgets are not known at compile time (e.g., populating a column of radio buttons based on data retrieved from the Internet).
With that in mind, this chapter discuss the XML way to lay out Android activity views that way
In Android, the user interface is built using a hierarchy of View and ViewGroup objects. Views are basic UI elements like buttons and text fields, while ViewGroups serve as containers to hold other views and arrange their layout. The UI hierarchy is defined using XML layout files, which map XML elements to their corresponding View classes. These layout files are loaded and inflated into views at runtime. Views can also be created and added programmatically in code. Views handle drawing, interaction events, and other behaviors to display the UI to the user.
Day 8: Dealing with Lists and ListViewsAhsanul Karim
The document discusses ListViews and ListActivities in Android. It covers:
- How ListViews display scrollable lists using an Adapter to provide data and layouts
- How ListActivities simplify list handling by predefining list interaction methods
- Implementing ArrayAdapters with standard or custom layouts
- Improving performance by recycling list item views
- Creating custom adapters to define flexible row layouts
- Allowing row views to interact with the underlying data model
This document discusses various cybersecurity risks and best practices. It describes how attackers can compromise computers through vulnerabilities in web browsers, applications, and weak user access rights. Common cyber attacks like viruses, worms, Trojans, and botnets are also explained. The document recommends implementing security measures like firewalls, antivirus software, and strong passwords to help defend against these threats. Regular software updates and awareness of social engineering tactics are also emphasized as important aspects of cybersecurity defense.
This document discusses IT security awareness and provides information on key aspects of IT security. It defines the components of an IT system that require protection, including hardware, software, data, and users. It also outlines important security principles of confidentiality, integrity and availability. Various security threats are described, as well as methods to prevent threats such as policies, user awareness training, and security technologies like firewalls and encryption. The role of compliance with standards and ongoing security measures like intrusion detection are also covered.
More Related Content
Similar to Android practice of layout in application-chapter6
The document discusses Android layouts. It explains that Views are UI components like buttons and text views, and ViewGroups are containers that position Views. The main ViewGroups covered are LinearLayout, which positions Views vertically or horizontally, and RelativeLayout, which positions Views relative to each other or the parent container. Attributes like orientation, gravity, weight and margins are used to control View positioning.
The document outlines the requirements and topics to be covered in an Android training, including developing layouts using XML and Java, running and debugging Android applications, using intents and bundles to pass data between activities, and handling basic data storage using SQLite and memory management. It also provides references and questions for trainees to refer to for more information on Android development concepts and best practices.
The document discusses different types of views and view groups in Android user interface development. It describes layouts like LinearLayout, RelativeLayout and FrameLayout that extend the ViewGroup class. These layouts allow arranging views in different orientations using attributes like layout_width, layout_height, layout_weight etc. The document also talks about defining views and layouts in XML files or programmatically at runtime.
This document discusses Android layouts and UI components. It covers the View and ViewGroup classes, which represent basic UI building blocks. It then covers various layout types like LinearLayout, FrameLayout, RelativeLayout, TableLayout and GridLayout. For each layout, it provides an overview and examples of key XML attributes used to control the layout. It concludes by providing links to sample code and slides for further reference.
The document discusses various techniques for developing efficient Android user interfaces (UIs), including using adapters, view holders, pre-scaling bitmaps, custom views, custom layouts, and more. Adapters act as a bridge between data and views. View holders minimize finding views repeatedly. Pre-scaling bitmaps improves performance over scaling at runtime. Custom views and layouts allow defining user-defined UI elements instead of using pre-defined ones only.
The document discusses various techniques for developing efficient Android user interfaces (UIs), including using adapters, view holders, pre-scaling bitmaps, custom views, custom layouts, and more. Adapters act as a bridge between data and views. View holders minimize finding views repeatedly. Pre-scaling bitmaps improves performance over scaling at runtime. Custom views and layouts allow defining user-defined UI elements.
This post will walk you through Android ListView Tutorial for building simple and customized ListView using different Android adapters.
List is one of the most common UI patterns, which is being used extensively to display the collection of data elements in rows. In android ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array.
This document provides an overview of layouts and user interface design in Android. It discusses the basic building blocks of Android UIs which are Views and ViewGroups. It describes common layout types like LinearLayout, RelativeLayout and TableLayout that can be used to position Views. It also covers attributes like id, width/height, padding etc. that can customize View properties. The document demonstrates how to declare layouts in XML and set View attributes. It emphasizes keeping layout hierarchies shallow to optimize performance.
The document discusses various layout containers used in Android user interface design, including LinearLayout, RelativeLayout, and TableLayout. LinearLayout arranges widgets linearly in a vertical or horizontal orientation. Key properties for LinearLayout include orientation, weight, gravity, padding, and margin. RelativeLayout positions widgets relative to each other and the parent container using positional rules. TableLayout arranges widgets in a grid with rows and columns, where each row is defined by a TableRow container. The document provides examples and details on how to implement each type of layout.
This document discusses implementing a simple network data browsing app in Android. It covers using a ListView to display data retrieved from a network request using Volley, and connecting the ListView to data with a custom adapter. The implementation steps include importing necessary libraries, creating layouts, initializing Volley, generating UI elements, registering button click listeners, making network requests, and viewing results. Additional topics include tools like Postman and JSON parsers, basic Android components, views, view groups, listeners, ListView, intents, and sample code.
This document discusses ListViews and ListActivities in Android application development. It covers:
- ListViews display scrollable lists via an Adapter that provides data and converts it to list fields. Standard adapters include ArrayAdapter and CursorAdapter.
- ListActivities simplify handling lists by extending the Activity class and providing list management methods like setListAdapter() and onListItemClick().
- Adapters can use default or custom layouts and the ListView recycles views for performance. Interacting with the underlying data model is also demonstrated.
The document discusses various aspects of using the GridView control in ASP.NET such as binding data to the GridView, handling paging, sorting and editing. It describes properties like AllowPaging and events like PageIndexChanging. It provides code examples for binding data, handling sorting and paging. The document also discusses different field types that can be used in a GridView like BoundField, TemplateField and HyperLinkField.
This document provides an overview of using DroidDraw, a user interface designer for Android applications. It discusses how DroidDraw allows dragging and dropping widgets onto a screen layout to build a UI visually. Key aspects covered include choosing root layouts like LinearLayout, setting screen size, generating XML code from the designed UI, and exploring different tabs for layouts, properties, strings, and more. The document also provides a brief introduction to key concepts in Android like activities, services, content providers and resources.
The document discusses different layouts in Android, including ConstraintLayout and LinearLayout. ConstraintLayout allows flexible screen layout by defining constraints between views. Views can be constrained to the parent layout or other views. LinearLayout displays views in a single column or row, and options like weight, orientation, and dimensions control how views are distributed. The challenge is to create a calculator screen layout using these techniques.
UI layouts define the structure and organization of elements in an Android activity's user interface. There are two main options for declaring layouts: in XML files or programmatically in Java code. Common layout types include LinearLayout, RelativeLayout, TableLayout, and FrameLayout. Layout files use a tree structure with attributes like ID, width, height, and weight to position child views. This allows separation of UI design from activity code.
1) The document describes building a simple user interface with an XML layout containing an EditText field and a Button. It explains how to define the UI elements in XML and add string resources for the text labels.
2) Key steps include creating a LinearLayout, adding an EditText and Button, setting attributes like IDs and dimensions, and externalizing strings to a resources file for localization.
3) Running the app displays the basic UI layout with an input field and button as defined in the XML code.
While it is technically possible to create and attach widgets to your activity purely through Java code, the more common approach is to use an XML-based layout file. Dynamic instantiation of widgets is reserved for more complicated scenarios, where the widgets are not known at compile time (e.g., populating a column of radio buttons based on data retrieved from the Internet).
With that in mind, this chapter discuss the XML way to lay out Android activity views that way
In Android, the user interface is built using a hierarchy of View and ViewGroup objects. Views are basic UI elements like buttons and text fields, while ViewGroups serve as containers to hold other views and arrange their layout. The UI hierarchy is defined using XML layout files, which map XML elements to their corresponding View classes. These layout files are loaded and inflated into views at runtime. Views can also be created and added programmatically in code. Views handle drawing, interaction events, and other behaviors to display the UI to the user.
Day 8: Dealing with Lists and ListViewsAhsanul Karim
The document discusses ListViews and ListActivities in Android. It covers:
- How ListViews display scrollable lists using an Adapter to provide data and layouts
- How ListActivities simplify list handling by predefining list interaction methods
- Implementing ArrayAdapters with standard or custom layouts
- Improving performance by recycling list item views
- Creating custom adapters to define flexible row layouts
- Allowing row views to interact with the underlying data model
Similar to Android practice of layout in application-chapter6 (20)
This document discusses various cybersecurity risks and best practices. It describes how attackers can compromise computers through vulnerabilities in web browsers, applications, and weak user access rights. Common cyber attacks like viruses, worms, Trojans, and botnets are also explained. The document recommends implementing security measures like firewalls, antivirus software, and strong passwords to help defend against these threats. Regular software updates and awareness of social engineering tactics are also emphasized as important aspects of cybersecurity defense.
This document discusses IT security awareness and provides information on key aspects of IT security. It defines the components of an IT system that require protection, including hardware, software, data, and users. It also outlines important security principles of confidentiality, integrity and availability. Various security threats are described, as well as methods to prevent threats such as policies, user awareness training, and security technologies like firewalls and encryption. The role of compliance with standards and ongoing security measures like intrusion detection are also covered.
Major privacy and security breaches in 2013 exposed personal information of millions online. Hackers stole usernames and passwords from major websites like Facebook and credit card numbers from Target customers. Anonymous hacking groups also stole emails and passwords from the New York Times, Wall Street Journal and Twitter. The 15 worst data breaches of the 21st century similarly exposed credit card and personal information for hundreds of millions of customers from companies like TJX, Sony, and others.
Normalization is a logical database design method that minimizes data redundancy and reduces design flaws. It involves applying normal forms like 1NF, 2NF, and 3NF to break large tables into smaller subsets. The normal forms improve data integrity by preventing anomalies like insertion, update, and deletion anomalies. Applying the normal forms can result in relations that are in first, second, and third normal form, but additional steps may be needed to attain Boyce-Codd normal form, which further reduces anomalies from overlapping candidate keys.
Basic4ppc is a programming language designed for mobile applications development.
With Basic4ppc you can develop programs directly on the Pocket PC / Window Mobile or on the desktop
The general direction in which something tends to move.
A general tendency or inclination. Current style. The Internet is a global revolution in communication – as long as You use letters from the Western alphabet.
People want their own domains in their own languages.
PHP is a server-side scripting language designed for web development, but also used as a general-purpose programming language. Most of the websites are using PHP in their dynamic content
Android practice of layout in application-chapter6
1. Unit 6
Practice of Layout in Application
By
Dr. Ramkumar Lakshminarayanan
Introduction
Layout becomes the basic of designing the user interface of the android application. In this
unit we discuss about the relative layout and grid layout and discuss about the design of the
User Interface.
RelativeLayout
RelativeLayout lays out elements based on their relationships with one another, and with the
parent container. This is arguably the most complicated layout, and we need several
properties to actually get the layout we want.
Relative To Container
These properties will layout elements relative to the parent container.
android:layout_alignParentBottom – Places the bottom of the element on the bottom
of the container
android:layout_alignParentLeft – Places the left of the element on the left side of the
container
android:layout_alignParentRight – Places the right of the element on the right side of
the container
android:layout_alignParentTop – Places the element at the top of the container
android:layout_centerHorizontal – Centers the element horizontally within its parent
container
android:layout_centerInParent – Centers the element both horizontally and vertically
within its container
android:layout_centerVertical – Centers the element vertically within its parent
container
Relative To Other Elements
These properties allow you to layout elements relative to other elements on screen. The value
for each of these elements is the id of the element you are using to layout the new element.
Each element that is used in this way must have an ID defined using
android:id=”@+id/XXXXX” where XXXXX is replaced with the desired id. You use
“@id/XXXXX” to reference an element by its id. One thing to remember is that referencing
an element before it has been declared will produce an error.
android:layout_above – Places the element above the specified element
android:layout_below – Places the element below the specified element
2. android:layout_toLeftOf – Places the element to the left of the specified element
android:layout_toRightOf – Places the element to the right of the specified element
Alignment With Other Elements
These properties allow you to specify how elements are aligned in relation to other elements.
android:layout_alignBaseline – Aligns baseline of the new element with the baseline
of the specified element
android:layout_alignBottom – Aligns the bottom of new element in with the bottom
of the specified element
android:layout_alignLeft – Aligns left edge of the new element with the left edge of
the specified element
android:layout_alignRight – Aligns right edge of the new element with the right edge
of the specified element
android:layout_alignTop – Places top of the new element in alignment with the top of
the specified element
Here is a sample XML Layout, for example we have replaced the activity_main.xml with the
following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<Spinner
android:id="@+id/dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />
<Spinner
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />
</RelativeLayout>
3. activity_main.xml
strings.xml
Figure 6.1 Output of the learnapp using relative layout
Grid Layout
GridLayout was introduced with Android 4.0. This layout allows you to organize a
view into a Grid. GridLayout separates its drawing area into: rows, columns, and cells.
You can specify how many columns you want for define for each View in which row
and column it should be placed and how many columns and rows it should use. If not
specified GridLayout uses defaults, e.g. one column, one row and the position of
a View depends on the order of the declaration of the Views.
There is a difference between GridView and GridLayout. A GridView is a
ViewGroup that displays items in two-dimensional scrolling grid. The items in the grid come
from the ListAdapter associated with this view.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">LearnApp</string>
<string name="hello_world">Learn Android App</string>
<string name="menu_settings">Settings</string>
<string name="reminder">Your Appointment at</string>
<string name="done">Done</string>
</resources>
4. Because a GridView gets its data from a ListAdapter, the only data loaded in memory
will be the one displayed on screen. When ListAdapter is used as the type for your variable,
you are really interested in the interface. GridViews, much like ListViews reuse and recycle
their views for better performance.
Whereas a GridLayout is a layout that places its children in a rectangular grid.
It was introduced in API level 14, and was recently backported in the Support Library.
Its main purpose is to solve alignment and performance problems in other layouts.
The drawback of ested layouts; which fall into three basic categories:
Inability to control alignment along both axes simultaneously
Performance problems in hierarchies that are too deep
Unsuitability for design tools that support free-form editing
A simple example of the first problem is the following form:
Figure 6.2 Sample Screen
As the font and the text of the “Email address” label change, we want the label to
remain aligned with the baseline of the component to its right, and aligned with
the right edge of the label below it. It’s not possible to do this with nested LinearLayouts
because the label needs to be aligned with other components both horizontally and vertically.
To provide better support a new layout is added to the Android framework:
GridLayout, which can be used to solve the above problems by dividing the container’s real
estate into rows and columns. GridLayout uses a grid of infinitely-thin lines to separate its
drawing area into: rows, columns, and cells. It supports both row and column spanning,
which together allow a widget to occupy a rectangular range of cells that are next to each
other. We’ll use the words row, column, and cell in the text below as shorthand for row
group, column group and cell group respectively, where groups have one or more contiguous
elements.
5. Figure 6.3 “Email address” label can belong both to a row that is baseline-aligned, and
a column that is right-aligned
Similarities with LinearLayout
In fact, the APIs are so similar that changing a tag name from LinearLayout to
GridLayout in an XML file that uses LinearLayout will often produce a similar UI without
requiring any other changes.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"
android:columnCount="4">
<TextView
android:text="Email setup"
android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"/>
<TextView
android:text="You can configure email in just a few steps:"
android:textSize="16dip"
android:layout_columnSpan="4"
android:layout_gravity="left"/>
<TextView
android:text="Email address:"
android:layout_gravity="right"/>
<EditText
android:ems="10"/>
<TextView
android:text="Password:"
android:layout_column="0"
android:layout_gravity="right"/>
<EditText
android:ems="8"/>
<Space
android:layout_row="4"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"/>
<Button
android:text="Next"
android:layout_row="5"
android:layout_column="3"
/>
</GridLayout>
6. The first difference you’ll notice in the code is the absence of the WRAP_CONTENT
and MATCH_PARENT constants that normally adorn Android layout resources. You don’t
normally need to use these with GridLayout.
Row and Column Indices
The second thing you may notice in the XML resources is that widgets don’t always
explicitly define which cells they are to be placed in. Each widget’s layout parameters have
row and column indices that together define where the widget should be placed but when
either or both of these values are not specified, GridLayout supplies default values rather than
throwing an exception.
Automatic Index Allocation
As children are added to a GridLayout, it maintains a cursor position and a “high-
water mark” that it uses to place widgets in cells that don’t yet have anything in them.
When GridLayout’s orientation is vertical, all of the same principles apply, except
that the roles of the horizontal and vertical axes are exchanged.
If you want multiple views to be placed in the same cell, you have to define the
indices explicitly, as the default allocation procedure above is designed to place widgets in
separate cells.
Sizes, Margins and Alignment/Gravity
In GridLayout, specifying sizes and margins is done just as with a LinearLayout.
Alignment/gravity also works just like gravity in LinearLayout and uses the same
constants: left, top, right, bottom, center_horizontal, center_vertical, center, fill_horizontal,
fill_vertical and fill.
Summary
GridLayout’s feature set incorporates much of the functionality of the Android
framework’s existing general-purpose layouts As such, it provides a way to replace many
deeply nested view hierarchies with a single highly optimized layout implementation.