0% found this document useful (0 votes)
1 views

chap3mad linear

Chapter 3 discusses UI components and layouts in Android, focusing on the View and ViewGroup classes as foundational elements for creating user interfaces. It details various layout types, including LinearLayout and RelativeLayout, along with their attributes and how they can be defined in XML. The chapter emphasizes the importance of layout properties in organizing UI elements effectively within an application.

Uploaded by

tharforever97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

chap3mad linear

Chapter 3 discusses UI components and layouts in Android, focusing on the View and ViewGroup classes as foundational elements for creating user interfaces. It details various layout types, including LinearLayout and RelativeLayout, along with their attributes and how they can be defined in XML. The chapter emphasizes the importance of layout properties in organizing UI elements effectively within an application.

Uploaded by

tharforever97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

CHAPTER NO : 3

UI COMPONENTS AND
LAYOUTS
UI Layouts

 The basic building block for user interface is a View object


which is created from the View class and occupies a
rectangular area on the screen and is responsible for drawing
and event handling.
 View is the base class for widgets, which are used to create
interactive UI components like buttons, text fields, etc.
 The ViewGroup is a subclass of View and provides invisible
container that hold other Views or other ViewGroups and
define their layout properties.
 At third level we have different layouts which are subclasses
of ViewGroup class and a typical layout defines the visual
structure for an Android user interface and can be created
either at run time using View/ViewGroup objects or you can
declare your layout using simple XML file main_layout.xml
which is located in the res/layout folder of your project.
 Android Layout Types
 There are number of Layouts provided
by Android which you will use in almost
all the Android applications to provide
different view, look and feel.
Linear Layout
 LinearLayout is a
view group that
aligns all children in
a single direction,
vertically or
horizontally.
 Android LinearLayout
is a view group that
aligns all children in
either vertically or
horizontally.
 we are having two options
 1. fill_parent

 2. wrap_content

fill_parent_width
 change the “layout_width” to “fill_parent” now the

buttons width will fill in the remaining spaces, just as


big as its parent “linearlayout”, but buttons height is
still enough to enclose its content only.
wrap_content:
 a button component set “wrap_content” on both

width and height attribute. it tell android to display


the button big enough to enclose its content
LinearLayout Attributes
 Following are the important attributes specific to

LinearLayout −
1. android:id
 This is the ID which uniquely identifies the layout.

2. android:baselineAligned
 This must be a boolean value, either "true" or

"false" and prevents the layout from aligning its


children's baselines.
3. android:baselineAlignedChildIndex
 When a linear layout is part of another layout that

is baseline aligned, it can specify which of its


children to baseline align.
4. android:divider
 This is drawable to use as a vertical

divider between buttons. You use a color


value, in the form of "#rgb", "#argb",
"#rrggbb", or "#aarrggbb".
5. android:gravity
 This specifies how an object should

position its content, on both the X and Y


axes. Possible values are top, bottom,
left, right, center, center_vertical,
center_horizontal etc.
6. android:orientation
 This specifies the direction of

arrangement and you will use


"horizontal" for a row, "vertical" for a
column. The default is horizontal.
7. android:weightSum
 Sum up of child weight
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button android:id="@+id/btnStartService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="start_service"/>
<Button android:id="@+id/btnPauseService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="pause_service"/>

<Button android:id="@+id/btnStopService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="stop_service"/>

</LinearLayout>
Relative Layout
 RelativeLayout is a view group that
displays child views in relative positions.
 Android RelativeLayout enables you to
specify how child views are positioned
relative to each other. The position of
each view can be specified as relative to
sibling elements or relative to the
parent.
 RelativeLayout Attributes
 Following are the important attributes specific to

RelativeLayout −
1. android:id
 This is the ID which uniquely identifies the layout.

2. android:gravity
 This specifies how an object should position its

content, on both the X and Y axes. Possible values


are top, bottom, left, right, center, center_vertical,
center_horizontal etc.
3. android:ignoreGravity
 This indicates what view should not be affected by

gravity.
 Using RelativeLayout, you can align two elements by
right border, or make one below another, centered in
the screen, centered left, and so on. By default, all
child views are drawn at the top-left of the layout, so
you must define the position of each view using the
various layout properties available from
RelativeLayout.LayoutParams and few of the
important attributes are given below −
1. android:layout_above
Positions the bottom edge of this view above the given
anchor view ID and must be a reference to another
resource, in the form "@[+][package:]type:name"
2. android:layout_alignBottom
 Makes the bottom edge of this view match the

bottom edge of the given anchor view ID and


must be a reference to another resource, in
the form "@[+][package:]type:name".
3. android:layout_alignLeft
 Makes the left edge of this view match the left

edge of the given anchor view ID and must be


a reference to another resource, in the form
"@[+][package:]type:name".
4. android:layout_alignParentBottom
 If true, makes the bottom edge of this view match

the bottom edge of the parent. Must be a boolean


value, either "true" or "false".
5. android:layout_alignParentEnd
 If true, makes the end edge of this view match the

end edge of the parent. Must be a boolean value,


either "true" or "false"
6. android:layout_alignParentLeft
 If true, makes the left edge of this view match the

left edge of the parent. Must be a boolean value,


either "true" or "false".
7. android:layout_alignParentRight
 If true, makes the right edge of this view match the

right edge of the parent. Must be a boolean value,


either "true" or "false".
8. android:layout_alignParentStart
 If true, makes the start edge of this view match the

start edge of the parent. Must be a boolean value,


either "true" or "false".
9. android:layout_alignParentTop
 If true, makes the top edge of this view match the

top edge of the parent. Must be a boolean value,


either "true" or "false".

You might also like