layouts and views

28
Layouts And Views

Upload: melvinf

Post on 18-Feb-2016

222 views

Category:

Documents


4 download

DESCRIPTION

Android tutorial

TRANSCRIPT

Page 1: Layouts and Views

Layouts And Views

Page 2: Layouts and Views

Views & Layouts

Page 3: Layouts and Views

Declaring Layouts

• Declare UI elements in XML.• Instantiate layout elements at runtime.

Page 4: Layouts and Views

Declare UI elements in XML

Page 5: Layouts and Views

Container Properties.

• Orientation• Gravity• Padding• Text• Id

Page 6: Layouts and Views

Load the XML Resource

Page 7: Layouts and Views

LayoutsDifferent Layouts supported by Android

• Frame Layout: all child views are pinned to the top left corner of the screen

• Linear Layout: each child view is added in a straight line (vertically or horizontally)

• Table Layout: add views using a grid of rows and columns

Page 8: Layouts and Views

• Relative Layout : add views relative to the position of other views or to its parent.

• Absolute Layout : for each view you add,

you specify the exact screen coordinate to display on the screen

• Tab Layout : add different tab relative to each other

Page 9: Layouts and Views

Views• Text View• Button• Edit Text• Radio button• Checkbox• Spinner• Web View• Image View• Gallery View• Grid View

Page 10: Layouts and Views

1. LinearLayout

Page 11: Layouts and Views
Page 12: Layouts and Views
Page 13: Layouts and Views

2. RelativeLayout

Page 14: Layouts and Views
Page 15: Layouts and Views

res/values/strings.xml

Page 16: Layouts and Views

res/values/colors.xml

Page 17: Layouts and Views
Page 18: Layouts and Views

3. TableLayout

• TableLayout– Root tag for tablelayout.

• TableRow.– Represents individual rows.

Page 19: Layouts and Views
Page 20: Layouts and Views

4. TabLayout

• TabHost• Root tag for Tablayout.

• TabWidget:• Tab title.

• FrameLayout• Tab body content.

Page 21: Layouts and Views
Page 22: Layouts and Views

Steps for Tab Creation• Create an Intent to launch an Activity for the tab.

– intent = new Intent().setClass(this, Artists.class);• Initialize a TabSpec for each tab.

– spec = tabHost.newTabSpec("artists")• Add title to TabSpec for each tab.

– tabSpec.setIndicator(“Tab Title", res.getDrawable(R.drawable.icon));

• Add it to the TabHost.– tabSpec.setContent(intent);

• Set initial tab to be displayed– tabHost.setCurrentTab(indexNo);

Page 23: Layouts and Views
Page 24: Layouts and Views

Binding External Data to Layouts.

• Grid• BaseAdapter

• ListView• ArrayAdapter

• Gallery• BaseAdapter

• SpinnerView• ArrayAdapter

Page 25: Layouts and Views

6. Grid

Page 26: Layouts and Views

res/layout/grid.xml

Page 27: Layouts and Views

7. ListView

Page 28: Layouts and Views

Customized Widget

• User defined View• User defined Layout