Download presentation
Presentation is loading. Please wait.
Published byChristina Sherman Modified over 9 years ago
1
Android Development: Application Layout Richard S. Stansbury 2015
2
Linear Layout: Fill Default: older layout elements have higher priority when it comes to display real estate Consider the following scenario: – Linear layout with three children – The first child has “wrap_content” – The second child has “match_parent” – Regardless of its configuration, a third child would not have space
3
Linear Layout: Weight Some people were a bit confused about weight when it came to the last build activity. Details… Weight by default for a component is zero (0) Weight indicates the proportion of the real-estate that a widget gets – Two widgets of equal weight will have equal space. – If widget 1’s weight is 2 and widget 2’s weight is 1, then widget 1 will have twice the space of widget 2.
4
Linear Layout: Weight Continued Allocating a percentage of space is possible (vertical orientation) – Set heights to zero – Set weights for each component to percentage of real-estate you want to give the component – Weights 50, 20, 30 would result in an widget 1 having 50%, widget 2 20%, and widget 3 having 30%
5
Gravity Gravity within the widget – Where does the content of the widget align within its borders Gravity within the space of a layout
6
Relative Layout Supports: – Alignment relative to the container – Alignment relative to other objects XML parameters for alignment within the container (set true or false): – Android:layout_alignParentTop – Android:layout_alignParentBottom – Android:layout_alignParentLeft – Android:layout_alignParentRight – Android:layout_centerInParent – Android:layout_centerHorizontal – Android:layout_centerVertical See also: http://developer.android.com/reference/android/widget/RelativeL ayout.LayoutParams.html
7
Relative Layout (continued) Relative to other widgets – Android. = “@id/ ” or, “@+id/ ” if first use of Position parameters: android:layout_above android:layout_below android:layout_toLeftOf android:layout_toRightOf
8
Relative Layout (continued) Alignment Parameters – android:layout_alignTop – android:layout_alignBottom – android:layout_alignLeft – android:layout_alignRight – android:layout_alignBaseline Base line is the implicit line in which text sits – e.g. for two buttons the labels of the buttons would align vertically Processed in two passes so you can align to things that have not yet been declared and vice-versa
9
Example How would you implement this view? – Components? – Alignments
10
Relative Layout and Overlap Relative Layout supports overlap with each new item being added to a higher layer in the z direction – i.e. newer stuff sits on top of older stuff Consider a background image with content on top.
11
Table Layout TableLayout defines a view in which content is divided into rows. – TableRow defines a new row – Content added to the TableRow are divided into columns – Total number of columns for the table is equal to the maximum number of columns across all defined rows – At least one column per widget
12
Table Layout (cont) parameters – Widgets filled left to right unless a a widget is given an explicit column android:layout_column = “ ” – Where is indexed from zero (0) – Each widget consumes one column – Column span can be set to extended across multiple columns android:layout_span = “ ”
13
Table Layout Column manipulation – Parameters for a specific column number can be set as a parameter to the TableLayout Stretch – android:stretchColumns – setColumnShrinkable Shrink – android:shrinkColumns – setColumnStretchable() Collapse – Make a column invisible android:collapseColumns setColumnCollapsed()
14
Example How many rows? How many columns? How do we get the EditText field to span remainder of table? How do we move Reset and Submit to the right?
15
ScrollView A scroll view can be a layout of layouts. Allows support for smaller devices lacking screen real-estate - vertical scroll - horizontal scroll view (Android 1.5 or later)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.