2. VIEW GROUPS
View Groups are a collection of views. (Container for views)
There can only be one root view. So if we have more than one view, we
need to put them in a view group
3.
4.
5.
6. TYPES OF VIEW GROUPS
Linear Layout
Relative Layout
7. LINEAR LAYOUT
It can arrange its children in a vertical column
Notice that we are not limited to just one textview and one imageview.
We can have as many as we want.
45. RELATIVE TO OTHER VIEWS
When positioning views relative to other views, you can constraints eg;
One view must be above the other
Or one imageView must be to the left of another
+View Groups are a collection of views.
+There can only be one root view. So if we have more than one view, we need to put them in a view group.
+A view group is a container of views.
+When a view group contains chi
+The red and orange rectangles are view groups
+They can have a width, height, background color or other attributes
+Background color can also be transparent so its not visible to the user
+If a view contains other views, we call it the parent of the views
+If a view is inside of a view group, we call it a child of that view group
+If there are multiple children, then each of those children are siblings to each other
A child imageview aligned to the top of the parent
A child textview aligned to the bottom of the parent
This also works for aligning to parents left or right edge as well as the center
This is a little more code that we are used
Make some ob servations about this code. The parent code is in red and the child code is blue
Go to the visualizer and examin the tags on the XML
Open the android documentation for linear layout. Google “android orientation” s
Link to the XML visualizer
HINT: Use the Layout cheat sheet to copy and paste the code
+View group layout parameters/attributes are handled by the parent e.g layout_width
Here are the words we introduced in this video:
match_parent
ViewGroup layout parameter
Go to the visualiser and demonstrate how changing the layout weights can vary the size of the views
Go to the visiualiser : http://labs.udacity.com/android-visualizer/#/android/linear-layout-weight
and create the above view
Summary For Linear layouts.
+A Linear Layout can have a vertical orientation or a horizontal orientation
+The individual views can have a weight values to fill up the extra space
This relative layout is set to have width of match_parent and height of mach_parent so its as big as the device
How children can be aligned
The other values are false by default so you don’t need to include them in the element tag
There are even more attributes that you can set. Eg centerHorizontal
By default all views are aligned to the left of the parent as seen in this slide
+http://labs.udacity.com/android-visualizer/#/android/relative-layout-align-to-parent
Go To code here: https://gist.github.com/anonymous/e7eb5ceff9dedfc376eb
We would start with these view. The will act as the anchor views
The rest will be positioned relative to these
So wee need to specify view IDs for the reference while positioning views
This is how we assign view IDs
We can assign view IDs to any view
Go to the documentation website to read about more attributes
Go to link: http://labs.udacity.com/android-visualizer/#/android/relative-layout-list-item
Go to this link to demo: http://labs.udacity.com/android-visualizer/#/android/padding-and-margin