Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application Development for mobile Devices

Similar presentations


Presentation on theme: "Application Development for mobile Devices"— Presentation transcript:

1 Application Development for mobile Devices
Know The Interface Application Development for mobile Devices

2 Interface Activity displays userinterface of your application which contains widgets like buttons ,textboxes and labels

3 Interface We define UI in xml file(reslayoutmain.xml)
During the runtime we load this UI to OnCreate() eventHandler in the Activity class , During the compilation ,each element in the xml file is compiled into its equivalent Android GUI class ,with attributes represented by methods

4 Views and ViewsGroups An activity contains views and views groups,a view is a widget that has appearance on the screen,example of views are buttons,labels and textboxes views derives from android.view.Views One or more views can be grouped into the viewGroup.A view group is a layout in which you can order and sequence of views(androidviewViewGroup)

5 ViewGroup linearLayout AbsoluteLayout RelativeLayout TableLayout
FrameLayout ScrollView

6 Attributes used in view and viewGroups

7 Units of measurement

8 Difference between dp and px
The dp unit is density independent and 160dp is equivalent to one inch. The px unit corresponds to an actual pixel on screen. You should always use the dp unit because it enables your activity to scale properly when run on devices of varying screen size.

9 emulator (320*480) emulator wit (480*800)

10

11 android:layout_width=”105dp” android:layout_height=”wrap_content”
<?xml version=”1.0” encoding=”utf-8”?> <LinearLayout xmlns:android=” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” > <TextView android:layout_width=”105dp” android:layout_height=”wrap_content” /> <Button android:layout_width=”160dp” android:text=”Button” android:layout_gravity=”right” android:layout_weight=”0.2” <EditText android:textSize=”18sp” android:layout_weight=”0.8” </LinearLayout>

12 layout_height and layout_width
Defines how much space this widget is asking from its parent layout to display itself. Although you could enter a value in pixels, inches, or something similar, that is not a good practice. Since your application could run on many different devices with various screen sizes, you want to use relative size for your components, not absolute. So, best practice would be to use either fill_parent or wrap_content for the value. fill_parent means that your widget wants all the available space from its parent. wrap_content means that it requires only as much space as it needs to display its own content. Note that in API Level 8 and higher, fill_parent has been renamed to match_parent.

13 layout_weihgt Layout weight is a number between 0 and 1. It implies the weight of our layout requirements. For example, if our Status EditText had a default layout weight of 0 and required a layout height of fill_parent, then the Update button would be pushed out of the screen because Status and its request for space came before the button. However, when we set the Status widget’s layout weight to 1, we are saying we want all available space height-wise, but are yielding to any other widget that also may need space, such as the Update button.

14 Layout_gravity Specifies how this particular widget is positioned within its layout, both horizontally and vertically. Values could be top, center, left, and so on. Notice the difference between this property and gravity, explained next. For example, if you have a widget that has its width set to fill_parent, trying to center it wouldn’t do much, because it’s already taking all available space. However, if our Title Text View had its width set to wrap_content, centering it with layout_gravity would generate the desired results.

15 gravity Specifies how the content of this widget is positioned within the widget itself. It is commonly confused with layout_gravity. Which one to use will depend on the size of your widget and the desired look. For example, if our Title TextView had the width fill_parent, then centering it with gravity would work, but centeringit with layout_gravity wouldn’t do anything.

16 Absolute_layout It enables you to specify the exact location of its children. Why do we not use Abslute_layout With the advent of devices with different screen sizes, using the AbsoluteLayout makes it difficult for your application to have a consistent look and feel across devices.

17 TableLayout The TableLayout groups views into rows and columns. You use the <TableRow> element to designate a row in the table. Each row can contain one or more views. Each view you place within a row forms a cell. The width of each column is determined by the largest width of each cell in that column.

18 Table Layout <?xml version=”1.0” encoding=”utf-8”?>
xmlns:android=” android:layout_height=”fill_parent” android:layout_width=”fill_parent” > <TableRow> <TextView android:text=”User Name:” android:width =”120px” /> <EditText android:width=”200px” /> </TableRow> android:text=”Password:” android:password=”true” <TextView /> <CheckBox android:layout_height=”wrap_content” android:text=”Remember Password” <Button android:text=”Log In” /> </TableLayout>

19 Relative layout The RelativeLayout enables you to specify how child views are positioned relative to each other.

20 (activity8)Listening for UI notifications
User interact with UI at two levels Activity level Views level At activity level Activity class exposes methods that you can override.. onKeyDown()---Called when a key was pressed and not handled by any of the views contained with in the acitvity onKeyUp()--- onMenuItemSelected()— onMenuOpened()----

21 When to use “@android or ?android”
is used for resources that are defined in your project or the Android framework. The ?-syntax is used for resources in the current theme. For starStyle, which should be defined in the theme "?android:attr/starStyle"


Download ppt "Application Development for mobile Devices"

Similar presentations


Ads by Google