Professional Documents
Culture Documents
Each layout has a set of attributes which define the visual properties of
that layout. There are few common attributes among all the layouts and
their are other attributes which are specific to that layout.
Sr.No. Attribute Description
This is the ID which uniquely
1 android:id
identifies the view.
2 android:layout_width This is the width of the layout.
3 android:layout_height This is the height of the layout
This is the extra space on the top
4 android:layout_marginTop
side of the layout.
This is the extra space on the
5 android:layout_marginBottom
bottom side of the layout.
Here width and height are the dimension of the layout/view which can be
specified in terms of dp (Density-independent Pixels), sp ( Scale-independent
Pixels), pt ( Points which is 1/72 of an inch), px( Pixels), mm ( Millimeters) and
finally in (inches).
Unit Description
dp Density-independent pixel. 1 dp is equivalent to one pixel on
a 160 dpi screen.
sp Scale-independent pixel. This is similar to dp and is
recommended for specifying font sizes
pt Point. A point is defined to be 1/72 of an inch, based on the
physical screen size.
px Pixel. Corresponds to actual pixels on the screen
OnClickListener()
onClick() This is called when the user either clicks or touches or focuses upon any widget like button, text, image etc.
You will use onClick() event handler to handle such event.
OnLongClickListener()
onLongClick() This is called when the user either clicks or touches or focuses upon any widget like button, text, image etc. for
one or more seconds. You will use onLongClick() event handler to handle such event.
OnFocusChangeListener()
onFocusChange() This is called when the widget looses its focus ie. user goes away from the view item. You will use
onFocusChange() event handler to handle such event.
OnFocusChangeListener()
onKey() This is called when the user is focused on the item and presses or releases a hardware key on the device. You
will use onKey() event handler to handle such event.
OnTouchListener()
onTouch() This is called when the user presses the key, releases the key, or any movement gesture on the screen. You will
use onTouch() event handler to handle such event.
OnMenuItemClickListener()
onMenuItemClick() This is called when the user selects a menu item. You will use onMenuItemClick() event handler to handle such
event.
onCreateContextMenuItemListener()
onCreateContextMenu()
This is called when the context menu is being built(as the result of a sustained "long click)
UNIT - II ANDROID UI DESIGN
22
MS. DIPALI B. TAWAR
Adapter in Android
•Adapter is a bridge between UI component and data source that helps us
to fill data in UI component. It holds the data and send the data to
an Adapter view then view can takes the data from the adapter view and
shows the data on different views like
as ListView, GridView, Spinner etc. For more customization in Views
we uses the base adapter or custom adapters.
•To fill data in a list or a grid we need to implement Adapter. Adapters
acts like a bridge between UI component and data source. Here data
source is the source from where we get the data and UI components are
list or grid items in which we want to display that data.
•A contextual menu is a
floating menu. It appears
only when the users
long-press an element or
right clicks on that. It
generally affects the select
• Its position is not fixed and
usually appears just beside
the element you did a long
press. ed element.
onCreate() The system calls this method when creating the fragment. We should
initialize essential components of the fragment that we want to retain
when the fragment is paused or stopped, then resumed.
onCreateView() The system calls this callback when it's time for the fragment to draw its
user interface for the first time. To draw a UI for your fragment, you
must return a View component from this method that is the root of your
fragment's layout. You can return null if the fragment does not provide a
UI.
onActivityCreated() The onActivityCreated() is called after the onCreateView() method when the
host activity is created. Activity and fragment instance have been created as
well as the view hierarchy of the activity. At this point, view can be accessed
with the findViewById() method. example. In this method you can instantiate
objects which require a Context object.
onStart() The onStart() method is called once the fragment gets visible.
onPause() The system calls this method as the first indication that the user is leaving the
fragment. This is usually where you should commit any changes that should
be persisted beyond the current user session.`
onDestroy() onDestroy() called to do final clean up of the fragment's state but Not
guaranteed to be called by the Android platform.