Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.

Similar presentations


Presentation on theme: "Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an."— Presentation transcript:

1 Android UserInterfaces Nasrullah Niazi

2 overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.

3 Each viewGroup is an invisible container that organizes views while View are widgets and controls that draw some part of UI.

4

5 Layouts A layout defines the visual structure for a user interface, such as the UI for an activity or app widget You can declare a layout in two ways. 1.Declare UI elements in XML. 2.Instantiate layout elements at runtime The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior

6 Questions 1 In order to create views and reference them from the application you use ?

7 Attributes android:id="@+id/my_button“ android:id="@android:id/empty“ Local resoures and android resources (android.R.) (R.id

8 Layout Parameters XML layout attributes named layout_something define layout parameters for the View that are appropriate for the ViewGroup in which it resides (layout_width and layout_height) wrap_content tells your view to size itself to the dimensions required by its content fill_parent (renamed match_parent in API Level 8) tells your view to become as big as its parent view group will allow.

9 The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel. getLeft() and getTop() getLeft()getTop() The latter returns the top, or Y, coordinate of the rectangle representing the view. These methods both return the location of the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.

10 Linear Layout It is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute

11 LinearLayout

12 android:layout_weight This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. For example, if there are three text fields and two of them declare a weight of 1, while the other is given no weight, the third text field without weight will not grow and will only occupy the area required by its content. The other two will expand equally to fill the space remaining after all three fields are measured. If the third field is then given a weight of 2 (instead of 0), then it is now declared more important than both the others, so it gets half the total remaining space, while the first two share the rest equally.

13 Relative Layout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left of center).

14

15 ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

16 GridViews that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter.


Download ppt "Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an."

Similar presentations


Ads by Google