Android Presentation

Android introduction l.jpg
1 / 25
1410 days ago, 485 views
PowerPoint PPT Presentation

Presentation Transcript

Slide 1

Android Introduction Hello Views Part 1 @2010 Mihail L. Sichitiu

Slide 2

Goal Familiarize with the fundamental sorts of GUI parts Concepts: Layouts Widgets Menus @2010 Mihail L. Sichitiu

Slide 3

Linear Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=""   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <LinearLayout   android:orientation="horizontal"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:layout_weight="1">   <TextView   android:text="red"   android:gravity="center_horizontal" [… … .]    </LinearLayout>   <LinearLayout   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:layout_weight="1">   <TextView   android:text="row one"   android:textSize="15pt"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:layout_weight="1"/>   <TextView   android:text="row two"   android:textSize="15pt"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:layout_weight="1"/> [… … ..]   </LinearLayout> </LinearLayout> exercises/sees/hi linearlayout.html @2010 Mihail L. Sichitiu

Slide 4

One Layout, two perspectives XML File versus Layout Preview @2010 Mihail L. Sichitiu

Slide 5

Relative Layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=""   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <TextView   android:id="@+id/label"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="Type here:"/>   <EditText   android:id="@+id/entry"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:background="@android:drawable/editbox_background"   android:layout_below="@id/label"/>   <Button   android:id="@+id/ok"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_below="@id/entry"   android:layout_alignParentRight="true"   android:layout_marginLeft="10dip"   android:text="OK"/>   <Button   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_toLeftOf="@id/ok"   android:layout_alignTop="@id/ok"   android:text="Cancel"/> </RelativeLayout> @2010 Mihail L. Sichitiu

Slide 6

Table Layout <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android=""   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:stretchColumns="1">   <TableRow>   <TextView   android:layout_column="1"   android:text="Open..."   android:padding="3dip"/>   <TextView   android:text="Ctrl-O"   android:gravity="right"   android:padding="3dip"/>   </TableRow>   <TableRow>   <TextView   android:layout_column="1"   android:text="Save..."   android:padding="3dip"/>   <TextView   android:text="Ctrl-S"   android:gravity="right"   android:padding="3dip"/>   </TableRow>   <TableRow>   <TextView   android:layout_column="1"   android:text="Save As..."   android:padding="3dip"/>   <TextView   android:text="Ctrl-Shift-S"   android:gravity="right"   android:padding="3dip"/>   </TableRow>   <View   android:layout_height="2dip"   android:background="#FF909090"/> [… … ] </TableLayout> @2010 Mihail L. Sichitiu

Slide 7

TabLayout One action for each tab Create new Project HelloTabs @2010 Mihail L. Sichitiu

Slide 8

Create three new exercises Right tap on HelloTabs Package Name - > New - > Class Right tap on the new class, Source - > Override/Implement Methods - > Check OnCreate(); @2010 Mihail L. Sichitiu

Slide 9

Fill in the OnCreate() strategy open class ArtistsActivity develops Activity {   open void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   textview = new TextView(this);   textview.setText("This is the Artists tab");   setContentView(textview);   } Quick and grimy "by hand" like in HelloWorld Copy and Paste ArtistsActivity into two more exercises: AlbumsActivity and SongsActivity @2010 Mihail L. Sichitiu

Slide 10

Copy the symbols Right snap - > Save As, Make ./res/drawable move the symbols into ./res/drawable @2010 Mihail L. Sichitiu

Slide 11

Create ./res/drawable/ic_tab_artists.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="">   <!- - When chosen, utilize dark - >   <item android:drawable="@drawable/ic_tab_artists_grey"   android:state_selected="true"/>   <!- - When not chose, utilize white- - >   <item android:drawable="@drawable/ic_tab_artists_white"/> </selector> StateListDrawable protest that presentations distinctive pictures for various conditions of a View @2010 Mihail L. Sichitiu

Slide 12

Make duplicates or the xml documents for the other two tabs: Copy the xml record: ic_tab_artists.xml - > ic_tab_albums.xlm - > ic_tab_songs.xml @2010 Mihail L. Sichitiu

Slide 13

Main Layout <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android=""   android:id="@android:id/tabhost"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <LinearLayout   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:padding="5dp">   <TabWidget   android:id="@android:id/tabs"   android:layout_width="fill_parent"   android:layout_height="wrap_content"/>   <FrameLayout   android:id="@android:id/tabcontent"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:padding="5dp"/>   </LinearLayout> </TabHost> @2010 Mihail L. Sichitiu

Slide 14

OnCreate() for HelloTabs (primary movement) open void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources();/Resource question get Drawables tabHost = getTabHost();  //The action TabHost TabHost.TabSpec spec;  //Resusable TabSpec for every tab Intent purpose;  //Reusable Intent for every tab/Create an Intent to dispatch an Activity for the tab (to be reused) plan = new Intent().setClass(this, ArtistsActivity.class);/Initialize a TabSpec for every tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists",   res.getDrawable(R.drawable.ic_tab_artists))   .setContent(intent);   tabHost.addTab(spec);  /Do the same for alternate tabs [… … ]   tabHost.setCurrentTab(2); } Main Activity is a TabActivity – has a TabHost Builder mapping the assets to the tab Select Tab 2 @2010 Mihail L. Sichitiu

Slide 15

Run it! @2010 Mihail L. Sichitiu

Slide 16

List View List of scrollable things Application will acquire from ListActivity as opposed to Activity Create ./res/design/list_item.xml Layout for every thing @2010 Mihail L. Sichitiu

Slide 17

Override the OnCreate strategy Setup the rundown for this application, with this format and this substance open class HelloListView augments ListActivity {/** Called when the movement is initially made. */@Override open void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setLi