Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2 b: Android Layout Basics Topics

Similar presentations


Presentation on theme: "Lecture 2 b: Android Layout Basics Topics"— Presentation transcript:

1 Lecture 2 b: Android Layout Basics Topics
Review View Groups Using Layout weight to give you more control in a layout Namespaces Using the full device screen Lab2 Exercise 2 - Coffee Ordering App

2 ViewGroup Review A ViewGroup is a container for Views.
The most common ViewGroups are LinearLayout, RelativeLayout, and ConstraintLayout. A ViewGroup has rules on how its child Views are positioned within it.

3 LinearLayout A LinearLayout uses orientation to arrange child views in a vertical column or a horizontal column.

4 RelativeLayout RelativeLayout positions child views relative to the parent. It is useful for positioning children relative to other children.

5 ConstraintLayout ConstraintLayout is similar to RelativeLayout in that Views are positioned relative to siblings or parent. Constraint layouts were introduced to solve flexible alignment issues in responsive layouts.

6 Namespaces  xmlns:android= droid is a namespace. Namespaces are give you access all the defined Android attributes and tags. Since the attributes and tags are attached to this namespace, an autocomplete list will occur when you type android:. Namespaces serve as a convenience.

7 Using the full device screen
In most cases, apps are designed to occupy the entire screen of a given device. To do this, add a no action bar attribute/value to the <application> section within the AndroidManifest.xml file. <application </application>

8 Using Layout Weight Adding a layout weight provides more control in a layout. Layout_weight is an attribute that can be applied to Views within a LinearLayout. By default, all views have a weight of 0. Android will divide the available space up amongst the Views proportionately, depending on their weight values.

9 Example 1: The default weight is zero.
Each view occupies the minimum amount of space it needs.

10 Example 2: layout_weight is applied to the first view element.
The larger weight allows the first element to expand to fill the “remaining space” in the parent view.

11 Example 3: A weight of 1 is applied to all elements.
It is required that we set the layout_height to “0dp”. Space is divided by the weight sum.

12 Lab 2 Exercise 2: Create the app. See the next slide for structure.

13 Lab 2 Ex 2 Structure


Download ppt "Lecture 2 b: Android Layout Basics Topics"

Similar presentations


Ads by Google