Académique Documents
Professionnel Documents
Culture Documents
4
Android Phone Features
Virtual Keyboard
Instant Search & Web Browsing
Built-In support for SQLite
Widgets & Live Folders
Sharing made Instant
Voice Search
Android Architecture
6
User Interface (UI)
Made up of View &
ViewGroup objects
Many types of views &
viewgroups
View is base class of
widgets
ViewGroup is base class of
layouts
View is a graphical element
and occupies rectangular
area of screen
7
TextView
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1“
android:text=“This is Label on TextView"/>
8
EditText
<EditText
android:id="@+id/EditText01"
android:layout_height="wrap_content“
android:layout_width="wrap_content"
android:singleLine="true"
android:text="Edittext example"/>
9
Button
<Button
android:id=“@+id/click_button"
android:layout_height="wrap_content"
android:layout_width=“fill_parent"
android:text="Click to Execute"
android:onClick="selfDestruct" />
10
Button & Click Handler
<Button
android:id=“@+id/click_button"
android:layout_height="wrap_content"
android:layout_width=“fill_parent"
android:text="Click to Execute" />
12
LinearLayout
A Layout that arranges its children in a single column or a
single row
The direction of the row can be set by calling
setOrientation() or android:orientation in XML
You can also specify gravity, which specifies the alignment
of all the child elements
Children can grow to fill up any remaining space in the
layout by setting the weight of element
The default orientation is horizontal
13
14
Linear Layout XML
Layout Output
15
16
Orientation=Vertical
17
Orientation=Vertical
<TextView
android:text="red“
Weight Does Matter
android:gravity="center_horizontal“
android:background="#aa0000“
android:layout_width="fill_parent“
android:layout_height="wrap_content“
android:layout_weight="2"/>
18
RelativeLayout
19
20
RelativeLayout
21
Relative Layout Output
FrameLayout
22
23
TableLayout
Layout in Code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout.LayoutParams lp;
lp = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams textViewLP;
textViewLP = new LinearLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
TextView myTextView = new TextView(this);
myTextView.setText("Hello World, HelloWorld");
ll.addView(myTextView, textViewLP);
This.addContentView(ll, lp);
24
}