21
Know The Interface Application Development for mobile Devices

Know The Interface Application Development for mobile Devices

Embed Size (px)

Citation preview

Page 1: Know The Interface Application Development for mobile Devices

Know The Interface

Application Development for mobile Devices

Page 2: Know The Interface Application Development for mobile Devices

Interface

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

Page 3: Know The Interface Application Development for mobile Devices

Interface• We define UI in xml file(reslayoutmain.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

Page 4: Know The Interface Application Development for mobile Devices

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(androidviewViewGroup)

Page 5: Know The Interface Application Development for mobile Devices

ViewGroup

• linearLayout• AbsoluteLayout• RelativeLayout• TableLayout• RelativeLayout• FrameLayout• ScrollView

Page 6: Know The Interface Application Development for mobile Devices

Attributes used in view and viewGroups

Page 7: Know The Interface Application Development for mobile Devices

Units of measurement

Page 8: Know The Interface Application Development for mobile Devices

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.

Page 9: Know The Interface Application Development for mobile Devices

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

Page 10: Know The Interface Application Development for mobile Devices
Page 11: Know The Interface Application Development for mobile Devices

<?xml version=”1.0” encoding=”utf-8”?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”vertical”android:layout_width=”fill_parent”android:layout_height=”fill_parent”>

<TextViewandroid:layout_width=”105dp”android:layout_height=”wrap_content”android:text=”@string/hello”/>

<Buttonandroid:layout_width=”160dp”android:layout_height=”wrap_content”android:text=”Button”android:layout_gravity=”right”android:layout_weight=”0.2”/>

<EditTextandroid:layout_width=”fill_parent”android:layout_height=”wrap_content”android:textSize=”18sp”android:layout_weight=”0.8”/>

</LinearLayout>

Page 12: Know The Interface Application Development for mobile Devices

layout_height and layout_widthDefines 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.

Page 13: Know The Interface Application Development for mobile Devices

layout_weihgtLayout 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.

Page 14: Know The Interface Application Development for mobile Devices

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.

Page 15: Know The Interface Application Development for mobile Devices

gravitySpecifies 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.

Page 16: Know The Interface Application Development for mobile Devices

Absolute_layout

• It enables you to specify the exact location of its children.

Why do we not use Abslute_layoutWith 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.

Page 17: Know The Interface Application Development for mobile Devices

TableLayoutThe 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.

Page 18: Know The Interface Application Development for mobile Devices

Table Layout

Page 19: Know The Interface Application Development for mobile Devices

Relative layout

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

Page 20: Know The Interface Application Development for mobile Devices

(activity8)Listening for UI notifications• User interact with UI at two levels1. Activity level2. Views levelAt 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()----

Page 21: Know The Interface Application Development for mobile Devices

When to use “@android or ?android”• The @-syntax 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"