Date post: | 14-Apr-2018 |
Category: |
Documents |
Upload: | jojo-cansino |
View: | 238 times |
Download: | 0 times |
of 29
7/30/2019 08 Layouts
1/29
Programming with Android:Introduction
Engr. Julius S. Cansino
Programming with Android:Layouts
7/30/2019 08 Layouts
2/29
Views: outline
Main difference between a Drawable and a Viewreaction to events
Could be declared in an XML file
Could also be declared inside an Activity
Every view has a unique ID Use findViewById(int id) to get it
Views can be customized
7/30/2019 08 Layouts
3/29
Some useful methods
getLeft()
getTop() getMeasuredWidth()
getMeasuredHeight()
getWidth() getHeight()
requestLayout()
invalidate()
7/30/2019 08 Layouts
4/29
ViewGroup and layout
ViewGroup is a view container
It is responsible for placing other views on the
display
Every layout must extend a ViewGroup
Every view needs to specify: android:layout_height
android:layout_width
A dimension or one ofmatch_parent orwrap_conte
7/30/2019 08 Layouts
5/29
Layouts
Some layouts are pre-defined by Android
Some of these are
LinearLayout
RelativeLayout
TableLayout
FrameLayout
AbsoluteLayout
A layout could be declared inside another layou
7/30/2019 08 Layouts
6/29
LinearLayout
Dispose views on a single row or column, depen
on android:layout_orientation The orientation could also be declared via
setOrientation(int orientation)
orientation is one ofHORIZONTAL orVERTICAL
Has two other attributes: gravity
weight
7/30/2019 08 Layouts
7/29
LinearLayout
7/30/2019 08 Layouts
8/29
LinearLayout
7/30/2019 08 Layouts
9/29
LinearLayout
7/30/2019 08 Layouts
10/29
LinearLayout
7/30/2019 08 Layouts
11/29
LinearLayout weight
7/30/2019 08 Layouts
12/29
LinearLayout weight
7/30/2019 08 Layouts
13/29
LinearLayout gravity
7/30/2019 08 Layouts
14/29
LinearLayout gravity
7/30/2019 08 Layouts
15/29
LinearLayout problem
7/30/2019 08 Layouts
16/29
RelativeLayout
Disposes views according to the container or
according to other views The gravity attribute indicates what views are m
important to define the layout
Useful to align views
7/30/2019 08 Layouts
17/29
RelativeLayout
7/30/2019 08 Layouts
18/29
RelativeLayout
l i
7/30/2019 08 Layouts
19/29
RelativeLayout
T bl L
7/30/2019 08 Layouts
20/29
TableLayout
As the name say, similar to a Table
Has some attributes to customize the layout:
android:layout_column
android:layout_span
android:stretchColumns
android:shrinkColumns
android:collapseColumns
Each row is inside a element
T bl L t
7/30/2019 08 Layouts
21/29
TableLayout
7/30/2019 08 Layouts
22/29
TableLayout
T bl L t
7/30/2019 08 Layouts
23/29
TableLayout
FrameLayout and AbsoluteLayout
7/30/2019 08 Layouts
24/29
FrameLayout and AbsoluteLayout
FrameLayout
Adds an attribute, android:visibility
Makes the user able to define layouts managing the
visibility of views
AbsoluteLayout
Deprecated
Specify position with x and y
Pay attention to different resolutions
Adapters
7/30/2019 08 Layouts
25/29
Adapters
Used to visualize data
Make a ViewGroup to interact with data
Some methods:
isEmpty()
getItem(int position)
getCount()
getView()
AdapterView
7/30/2019 08 Layouts
26/29
AdapterView
A ViewGroup subclass
Its subchilds are determined by an Adapter
Some subclasses:
ListView
GridView
Spinner
Gallery
ListView example
7/30/2019 08 Layouts
27/29
ListView example
public class HelloAndroidActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
String[] data = {"First", "Second", "Third"};
ListView lv = (ListView)findViewById(R.id.list);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, data));
}
}
ListView
7/30/2019 08 Layouts
28/29
ListView
Other views/adapters
7/30/2019 08 Layouts
29/29
Other views/adapters
Spinner, selection of multiple items
Gallery, images
ExpandableListView, list with hidden values
TabWidget, tabbed layouts