SlideShare une entreprise Scribd logo
1  sur  14
Android Layout
 the basic building block for user interface is
a View object that is created from the View class and
occupies a rectangular area on the screen. Views are
the base class for UI components like TextView,
Button, EditText etc.
 the ViewGroup is a subclass of View. One or more
Views can be grouped together into a ViewGroup. A
ViewGroup provides the android layout in which we
can order the appearance and sequence of views.
Examples of ViewGroup
are LinearLayout, FrameLayout, RelativeLayout et
c.
Android Layout Types
Android provides the following ViewGroups or layouts:
 LinearLayout : is a ViewGroup that aligns all children
in a single direction, vertically or horizontally
 RelativeLayout : is a ViewGroup that displays child
views in relative positions
 Absolute Layout : allows us to specify the exact
location of the child views and widgets
 TableLayout : is a view that groups its child views
into rows and columns
 FrameLayout : is a placeholder on screen that is
used to display a single view
Android Layout Types
 ScrollView : is a special type of FrameLayout in that
it allows users to scroll through a list of views that
occupy more space than the physical display. The
ScrollView can contain only one child view or
ViewGroup, which normally is a LinearLayout
 List View : is a view group that displays a list of
scrollable item
 GridView : is a ViewGroup that displays items in two-
dimensional scrolling grid. The items in the grid
come from the ListAdapter associated with this view
two most used android layout:
LinearLayout
RelativeLayout
Android Layout Attributes
 android:id : This is the ID which uniquely identifies the view
 android:layout_width : This is the width of the layout
 android:layout_height : This is the height of the layout
 android:layout_margin : This is the extra space outside of the view.
For example if you give android:marginLeft=20dp, then the view will be
arranged after 20dp from left
 android:layout_padding : This is similar
to android:layout_margin except that it specifies the extra
space inside the view
 android:layout_gravity : This specifies how child Views are positioned
 android:layout_weight : This specifies how much of the extra space in
the layout should be allocated to the view
 android:layout_x : This specifies the x-coordinate of the layout
 android:layout_y : This specifies the y-coordinate of the layout
 android:layout_width=wrap_content tells the view to size itself to the
dimensions required by its content.
 android:layout_width=match_parent tells the view to become as big as
its parent view.
View Identification
The syntax for an ID, inside an XML tag is:
 The at-symbol (@) at the beginning of the string
indicates that the XML parser should parse and
expand the rest of the ID string and identify it as
an ID resource
 The plus-symbol (+) means that this is a new
resource name that must be created and added
to our resources
Android LinearLayout
 Android LinearLayout organizes elements along a
single line. We can specify whether that line is vertical
or horizontal using android:orientation. The orientation
is horizontal by default.
 A vertical LinearLayout will only have one child per
row (so it is a column of single elements), and a
horizontal LinearLayout will only have one single row
of elements on the screen.
 android:layout_weight attribute depicts the
importance of the element. An element with larger
weight occupies more screen space. Here is a sample
Layout XML using LinearLayout:
 layout_linear.xml
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="@dimen/activity_horizontal_margin"> <Button
android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:text="Row 2"
android:layout_width="wrap_content" android:textSize="18sp" android:layout_margin="10dp"
android:layout_height="wrap_content" /> <TextView android:text="Row 3"
android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:text="Row 4"
android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:text="Row 5"
android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <LinearLayout android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content"> <Button
android:id="@+id/next_button" android:text="next" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:text="Row 6b"
android:textSize="18sp" android:layout_margin="10dp" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView
android:text="Row 6c" android:textSize="18sp" android:layout_margin="10dp"
android:layout_gravity="center" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:text="Row 6d"
android:textSize="18sp" android:layout_margin="10dp" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
this layout we have a Parent LinearLayout which has a vertical orientation and contains buttons, textviews and a
nested Linear Layout(having a horizontal orientation) as child views.
Note: Nested layouts don’t have to be of one type. We could, for example, have a LinearLayout as one of the
Android RelativeLayout
 Android RelativeLayout lays out elements based on
their relationships with one another, and with the
parent container. This is one of the most complicated
layout and we need several properties to actually get
the layout we desire.
 That is, using RelativeLayout we can position a view
to be toLeftOf, toRightOf, below or above its
siblings.
 We can also position a view with respect to its parent
such as centered horizontally, vertically or both,
or aligned with any of the edges of the
parent RelativeLayout. If none of these attributes are
specified on a child view then the view is by default
rendered to the top left position.
Android RelativeLayout attributes
The following are the major attributes used across RelativeLayout.
They lay across three different categories:
Relative To Container
 android:layout_alignParentBottom : Places the bottom of the
element on the bottom of the container
 android:layout_alignParentLeft : Places the left of the element on
the left side of the container
 android:layout_alignParentRight : Places the right of the element
on the right side of the container
 android:layout_alignParentTop : Places the element at the top of
the container
 android:layout_centerHorizontal : Centers the element
horizontally within its parent container
 android:layout_centerInParent : Centers the element both
horizontally and vertically within its container
 android:layout_centerVertical : Centers the element vertically
within its parent container
Relative to Siblings
 android:layout_above : Places the element above the
specified element
 android:layout_below : Places the element below the
specified element
 android:layout_toLeftOf : Places the element to the
left of the specified element
 android:layout_toRightOf : Places the element to the
right of the specified element
 “@id/XXXXX” is used to reference an element by its
id. One thing to remember is that referencing an
element before it has been declared will produce an
error so @+id/ should be used in such cases.
Alignment With Other Elements
 android:layout_alignBaseline : Aligns baseline of
the new element with the baseline of the specified
element
 android:layout_alignBottom : Aligns the bottom of
new element in with the bottom of the specified
element
 android:layout_alignLeft : Aligns left edge of the
new element with the left edge of the specified
element
 android:layout_alignRight : Aligns right edge of
the new element with the right edge of the
specified element
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="https://schemas.android.com/apk/res/android"> <Button
android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <TextView android:id="@+id/firstName"
android:text="First Name" android:textSize="18sp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@id/backbutton" /> <TextView
android:id="@+id/editFirstName" android:text="JournalDev" android:textSize="18sp"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"
android:layout_height="wrap_content" android:layout_toRightOf="@id/firstName"
android:layout_below="@id/backbutton"/> <TextView android:id="@+id/editLastName"
android:text="Layout Tutorial Example" android:textSize="18sp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/lastName" android:layout_toRightOf="@+id/lastName"
android:layout_toEndOf="@+id/lastName" /> <TextView android:id="@+id/lastName"
android:text="Last Name" android:textSize="18sp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="48dp"
android:layout_below="@+id/firstName" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_marginRight="10dp"
android:layout_marginLeft="40dp" android:layout_marginStart="40dp" /> <Button
android:id="@+id/next" android:text="Next" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/editLastName"
android:layout_alignLeft="@+id/editLastName" android:layout_alignStart="@+id/editLastName"
android:layout_marginTop="37dp" /> </RelativeLayout>

Contenu connexe

Tendances

Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Elizabeth alexander
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaEdureka!
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_androidPRITI TELMORE
 
Android resources
Android resourcesAndroid resources
Android resourcesma-polimi
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development pptsaitej15
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development pptGautam Kumar
 
7) packaging and deployment
7) packaging and deployment7) packaging and deployment
7) packaging and deploymenttechbed
 
Android animation
Android animationAndroid animation
Android animationKrazy Koder
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & viewsma-polimi
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 

Tendances (20)

Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | Edureka
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
 
Android resources
Android resourcesAndroid resources
Android resources
 
Vb basics
Vb basicsVb basics
Vb basics
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development ppt
 
7) packaging and deployment
7) packaging and deployment7) packaging and deployment
7) packaging and deployment
 
Android animation
Android animationAndroid animation
Android animation
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Android activity
Android activityAndroid activity
Android activity
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
android layouts
android layoutsandroid layouts
android layouts
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 

Similaire à Android Layout.pptx

Similaire à Android Layout.pptx (20)

Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Android practice of layout in application-chapter6
Android practice of layout in application-chapter6Android practice of layout in application-chapter6
Android practice of layout in application-chapter6
 
Unit 2 LayoutTutorial.pptx
Unit 2 LayoutTutorial.pptxUnit 2 LayoutTutorial.pptx
Unit 2 LayoutTutorial.pptx
 
Layout
LayoutLayout
Layout
 
View groups containers
View groups containersView groups containers
View groups containers
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
01 08 - graphical user interface - layouts
01  08 - graphical user interface - layouts01  08 - graphical user interface - layouts
01 08 - graphical user interface - layouts
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
行動App開發管理實務unit3
行動App開發管理實務unit3行動App開發管理實務unit3
行動App開發管理實務unit3
 
4.pptx
4.pptx4.pptx
4.pptx
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
 
Android UI
Android UI Android UI
Android UI
 
Android Ui
Android UiAndroid Ui
Android Ui
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
 
Android xml-based layouts-chapter5
Android xml-based layouts-chapter5Android xml-based layouts-chapter5
Android xml-based layouts-chapter5
 
Support Design Library
Support Design LibrarySupport Design Library
Support Design Library
 

Plus de vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Dernier

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 

Dernier (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 

Android Layout.pptx

  • 2.  the basic building block for user interface is a View object that is created from the View class and occupies a rectangular area on the screen. Views are the base class for UI components like TextView, Button, EditText etc.  the ViewGroup is a subclass of View. One or more Views can be grouped together into a ViewGroup. A ViewGroup provides the android layout in which we can order the appearance and sequence of views. Examples of ViewGroup are LinearLayout, FrameLayout, RelativeLayout et c.
  • 3. Android Layout Types Android provides the following ViewGroups or layouts:  LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally  RelativeLayout : is a ViewGroup that displays child views in relative positions  Absolute Layout : allows us to specify the exact location of the child views and widgets  TableLayout : is a view that groups its child views into rows and columns  FrameLayout : is a placeholder on screen that is used to display a single view
  • 4. Android Layout Types  ScrollView : is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout  List View : is a view group that displays a list of scrollable item  GridView : is a ViewGroup that displays items in two- dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view
  • 5. two most used android layout: LinearLayout RelativeLayout
  • 6. Android Layout Attributes  android:id : This is the ID which uniquely identifies the view  android:layout_width : This is the width of the layout  android:layout_height : This is the height of the layout  android:layout_margin : This is the extra space outside of the view. For example if you give android:marginLeft=20dp, then the view will be arranged after 20dp from left  android:layout_padding : This is similar to android:layout_margin except that it specifies the extra space inside the view  android:layout_gravity : This specifies how child Views are positioned  android:layout_weight : This specifies how much of the extra space in the layout should be allocated to the view  android:layout_x : This specifies the x-coordinate of the layout  android:layout_y : This specifies the y-coordinate of the layout  android:layout_width=wrap_content tells the view to size itself to the dimensions required by its content.  android:layout_width=match_parent tells the view to become as big as its parent view.
  • 7. View Identification The syntax for an ID, inside an XML tag is:  The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource  The plus-symbol (+) means that this is a new resource name that must be created and added to our resources
  • 8. Android LinearLayout  Android LinearLayout organizes elements along a single line. We can specify whether that line is vertical or horizontal using android:orientation. The orientation is horizontal by default.  A vertical LinearLayout will only have one child per row (so it is a column of single elements), and a horizontal LinearLayout will only have one single row of elements on the screen.  android:layout_weight attribute depicts the importance of the element. An element with larger weight occupies more screen space. Here is a sample Layout XML using LinearLayout:  layout_linear.xml
  • 9. <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="@dimen/activity_horizontal_margin"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 2" android:layout_width="wrap_content" android:textSize="18sp" android:layout_margin="10dp" android:layout_height="wrap_content" /> <TextView android:text="Row 3" android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 4" android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 5" android:textSize="18sp" android:layout_margin="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/next_button" android:text="next" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 6b" android:textSize="18sp" android:layout_margin="10dp" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 6c" android:textSize="18sp" android:layout_margin="10dp" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Row 6d" android:textSize="18sp" android:layout_margin="10dp" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> this layout we have a Parent LinearLayout which has a vertical orientation and contains buttons, textviews and a nested Linear Layout(having a horizontal orientation) as child views. Note: Nested layouts don’t have to be of one type. We could, for example, have a LinearLayout as one of the
  • 10. Android RelativeLayout  Android RelativeLayout lays out elements based on their relationships with one another, and with the parent container. This is one of the most complicated layout and we need several properties to actually get the layout we desire.  That is, using RelativeLayout we can position a view to be toLeftOf, toRightOf, below or above its siblings.  We can also position a view with respect to its parent such as centered horizontally, vertically or both, or aligned with any of the edges of the parent RelativeLayout. If none of these attributes are specified on a child view then the view is by default rendered to the top left position.
  • 11. Android RelativeLayout attributes The following are the major attributes used across RelativeLayout. They lay across three different categories: Relative To Container  android:layout_alignParentBottom : Places the bottom of the element on the bottom of the container  android:layout_alignParentLeft : Places the left of the element on the left side of the container  android:layout_alignParentRight : Places the right of the element on the right side of the container  android:layout_alignParentTop : Places the element at the top of the container  android:layout_centerHorizontal : Centers the element horizontally within its parent container  android:layout_centerInParent : Centers the element both horizontally and vertically within its container  android:layout_centerVertical : Centers the element vertically within its parent container
  • 12. Relative to Siblings  android:layout_above : Places the element above the specified element  android:layout_below : Places the element below the specified element  android:layout_toLeftOf : Places the element to the left of the specified element  android:layout_toRightOf : Places the element to the right of the specified element  “@id/XXXXX” is used to reference an element by its id. One thing to remember is that referencing an element before it has been declared will produce an error so @+id/ should be used in such cases.
  • 13. Alignment With Other Elements  android:layout_alignBaseline : Aligns baseline of the new element with the baseline of the specified element  android:layout_alignBottom : Aligns the bottom of new element in with the bottom of the specified element  android:layout_alignLeft : Aligns left edge of the new element with the left edge of the specified element  android:layout_alignRight : Aligns right edge of the new element with the right edge of the specified element
  • 14. <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="https://schemas.android.com/apk/res/android"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/firstName" android:text="First Name" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/backbutton" /> <TextView android:id="@+id/editFirstName" android:text="JournalDev" android:textSize="18sp" android:layout_width="wrap_content" android:layout_marginLeft="10dp" android:layout_height="wrap_content" android:layout_toRightOf="@id/firstName" android:layout_below="@id/backbutton"/> <TextView android:id="@+id/editLastName" android:text="Layout Tutorial Example" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/lastName" android:layout_toRightOf="@+id/lastName" android:layout_toEndOf="@+id/lastName" /> <TextView android:id="@+id/lastName" android:text="Last Name" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="48dp" android:layout_below="@+id/firstName" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginRight="10dp" android:layout_marginLeft="40dp" android:layout_marginStart="40dp" /> <Button android:id="@+id/next" android:text="Next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editLastName" android:layout_alignLeft="@+id/editLastName" android:layout_alignStart="@+id/editLastName" android:layout_marginTop="37dp" /> </RelativeLayout>