
Lecture 4 widgets.ppt
- Количество слайдов: 29
Lecture #4 Layouts and Basic Widgets
Layouts List of standart layouts: 1) Frame. Layout 3) Linear. Layout 2) Table. Layout 4) Relative. Layout
Frame. Layout Views are upper-left corner aligned(over another) <? xrnl version="l. O" encoding="utf-8"? > <Frame. Layout xmlns: android="http: //schemas. android. com /apk/res/android" android: id="@+id/Frame. Layout. Ol" android: layout_height="wrap_content" android: layout_width="t'ill_parent"> <Button android: text="@+id/Button. Ol " android: id="@+id/Button. Ol" android: layout_width="wrap_content" android: layout_height="wrap_content"/> < / Frame. Layout>
Linear. Layout Aligns in either VERTICAL or HORIZONTAL direction ex: android: orientation = “horizontal” One after another in one row(height of a row = height of highest subview)
Linear. Layout <? xml version="l. O" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schernas. android. com/apk/res/android" android: id="@+id/Linear. Layout. Ol" android: layout_width="fill_parent" android: layout_height="fill_parent" android : orientation="horizontal"> <Button android: id="@+id/buttonl" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="Button. Ol"/> <Button android: id="@+id/button 2" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="Button 02"/> <Button android: id="@+id/button 3" android: layout_height="wrap_content" android: layout_width="fill_parent" android: text="Button. OЗ"/> </Linear. Layout>
Linear. Layout: weight <? xrnl version="l. O" encoding="utf-8"? > <Linear. Layout xrnlns: android="http: 1/schernas. android. com/apk/re s/android' || = || android: orientation="horizontal"> <Edit. Text android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_weight="0"/> <Edit. Text || = || android: layout_weight="l" /> <Edit. Text || = || android: layout_weight="2"/> </Linear. Layout>
Table. Layout Represents view in terms of ROWS & COLUMNS Table. Row object is used to define a single row Single row can contain several or no cells. Any object of View. Group can be putted in a cell
Table. Layout Table. Row properties: Layout height - wrap_content; Layout width - fill_parent; Gravity - center. Each button’s properties: Layout height - wrap_content; Layout width - 20 pt.
Relative. Layout Aligns with respect to parent view or its neighbors
Basics Widgets Text. View Edit. Text Scroll. View Horizontal. Scroll. View Image. View Button Check. Box Toggle. Button Radio. Button Image. Button Tab. Host Tab. Widget
Text. View From XML layout: android: text="Hello, Android! From Java Code: Text. View text = (Text. View) find. View. By. Id(R. id. t 2) ; text. set. Text("Hello, Android!"); Multilingual: android: text="@string/text_hello" Text. View text = (Text. View) find. View. By. Id(R. id. t 2) ; text. set. Text(R. string. text_hello); );
android: text. Size px - pixels dp - (density-independent pixels) sp - (scale-independent pixels) in - inches pt - 1/72 inch mm - millimeters android: text. Style normal, bold, italic android: text. Color #RGB, #RRGGBB, #ARGB, #AARRGGBB A-alpha(opacity)
Edit. Text Is designed to input/retrieve text information Methods: - get. Text() - returns text from Edit. Text field - select. All() - selects whole text in a window - set. Selection(int start, int stop) - selects an area from start to stop - set. Selection(int index) - put carriage(cursor) at index Most methods are overridden from Text. View class
Scroll. View & Horizontal. Scroll. View Inherit from View. Group => containers. Scroll. View supports only VERTICAL scrolling. To add horizontal scrolling => inline Horizontal. Scroll. View subview.
Image. View Graphics, icons, UI, . . . android: src = “@drawable/sdu” Methods: - set. Image. Resource(int res. Id) => from resources - set. Image. URI(Uri uri) => Uniform Resource Ident. . - set. Image. Bitmap(Bitmap bitmap) => raster graphics or bitmap loader - set. Max. Height(), set. Max. Width(), get. Scale. Type(), . .
Buttons
Button generally on. Click event handling is used. final Button b =(Button) find. View. By. Id (R. id. but) ;
public void on. Click (View v){switch (v. get. Id ( ) ){ case R. id. button_r: m. Edit. set. Typeface(null, Typeface. NORМAL) ; break; case R. id. button_b: m. Edit. set. Typeface(null, Typeface. BOLD) ; break; case R. id. button_i: m. Edit. set. Typeface(null, Typeface. ITALIC) ; break; case R. id. button_plus: if (m. Text. Size <= 72) m. Text. Size+=2 ; m. Edit. set. Text. Size (m. Text. Size ) ; break; case R. id. button_minus: if (m. Text. Size >= 20) m. Text. Size-=2 ; m. Edit. set. Text. Size (m. Text. Size) ; break; } }
Radio. Group & Radio. Button methods: - toggle() - is. Checked() - set. Checked()
Check. Box Flag with two states: ON, OFF For event handling use Compound. Button. On. Checked. Change. Listener
Toggle. Button with two conditions: ON/OFF Usual LED indicator, when ON -> Green Light Main properties: android: text. Off -> set. Text. Off() android: text. On -> set. Text. On() set. Checked(boolean checked) main action -> on. Checked. Changed()
Tab. Host & Tab. Widget Tab. Host is container for series of object of type Tab. Widget
Tab. Host - setup() - initializes tab container(before find. Vie. By. Id()) - add. Tab() - add new tab - set. Current. Tab() - front view for a tab Tabs have tabulation, information filling. Has to be defined in Tab. Spec: Tab. Host. Tab. Spec spec = tabs. new. Тab. Spec ("tagl"); spec. set. Content(R. id. tab. Page 1) ; spec. set. Indicator("Document 1") ; tabs. add. Tab(spec) ;
Read the rest at home Book name: “Голощапов А. Л. - Google Android программирование для мобильных устрои ств 2011” Available at: vk. com/sduandroid Chapter 5 and 6
Lecture 4 widgets.ppt