SlideShare a Scribd company logo
5
Most read
7
Most read
15
Most read
Layouts in android
Disclaimer:This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
LAYOUTS IN
 ANDROID
     Ashwin Anand V
     Email:ashwinanand99@gmail.com
     Facebook id:ashwinanand99@gmail.com
Android Layout
• An Android layout is a class that handles arranging the way its
children appear on the screen. Anything that is a View can be a
child of a layout.

• The standard layouts are,
    Linear
    Absolute
    Relative
    Frame
    Table
Absolute Layout
Absolute Layout is based on the simple idea of placing each
control at an absolute position.
    Specify the exact x and y coordinates on the screen for
   each control
    It was used rarely because it makes inflexibilities so very
   risk to maintain
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
       android:id="@+id/backbutton"
       android:text="Back"
       android:layout_x="10px"
       android:layout_y="5px"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <TextView
       android:layout_x="10px"
       android:layout_y="110px"
       android:text="First Name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <EditText
       android:layout_x="150px"
       android:layout_y="100px"
       android:width="100px"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <TextView
       android:layout_x="10px"
       android:layout_y="160px"
       android:text="Last Name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
       <EditText
       android:layout_x="150px"
       android:layout_y="150px"
       android:width="100px"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />               screenshot of the layout
</AbsoluteLayout>
Frame Layout
 Frame Layout is designed to display a single item at a time
 You can have multiple elements within a Frame Layout but each
element will be positioned based on the top left of the screen.
 Frame Layout can become more useful when elements are
hidden and displayed programmatically. You can use the attribute
android:visibility in the XML to hide specific elements
<FrameLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     xmlns:android="http://schemas.android.
com/apk/res/android">

    <ImageView
    android:src="@drawable/icon"
    android:scaleType="fitCenter"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"/>

     <TextView
     android:text="Learn-Android.com"
     android:textSize="24sp"
     android:textColor="#000000"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent"
     android:gravity="center"/>

</FrameLayout>

                                              screenshot of the layout
Linear Layout
Linear Layout organizes elements along a single line. You
specify whether that line is vertical or horizontal using
android:orientation. Here is a sample Layout XML using Linear
Layout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="horizontal"
       android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <Button
       android:id="@+id/backbutton"
       android:text="Back"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <TextView
       android:text="First Name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <EditText
       android:width="100px"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <TextView
       android:text="Last Name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
    <EditText
       android:width="100px"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
</LinearLayout>


                                                             screenshot of the layout
Relative Layout
Relative Layout lays out elements based on their relationships
with one another, and with the parent container. This is arguably
the most complicated layout, and we need several properties to
actually get the layout we want.
Relative To Container
These properties will layout elements relative to the parent
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 Other Elements
• 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

            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
• android:layout_alignTop – Places top of the new element in alignment with the top
of the specified element
<RelativeLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       xmlns:android="http://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:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@id/backbutton" />
       <EditText
              android:id="@+id/editFirstName"
              android:width="100px"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toRightOf="@id/firstName"
              android:layout_below="@id/backbutton"/>
       <EditText
              android:id="@+id/editLastName"
              android:width="100px"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@id/editFirstName"
              android:layout_alignLeft="@id/editFirstName"/>
       <TextView
              android:id="@+id/lastName"
              android:text="Last Name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toLeftOf="@id/editLastName"
              android:layout_below="@id/editFirstName" />
</RelativeLayout>
Table Layout
Table Layout organizes content into rows and columns. The rows
are defined in the layout XML, and the columns are determined
automatically by Android. This is done by creating at least one
column for each element.
You can specify that an element should occupy more than one
column using android:layout_span. This can increase the total
column count as well, so if we have a row with two elements
and each element has android:layout_span=”3″ then you will
have at least six columns in your table.
<TableLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       xmlns:android="http://schemas.android.com/apk/res/an
droid">
       <TableRow>
              <Button
              android:id="@+id/backbutton"
              android:text="Back"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
       </TableRow>
       <TableRow>
              <TextView
              android:text="First Name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_column="1" />
              <EditText
              android:width="100px"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
       </TableRow>
       <TableRow>
              <TextView
              android:text="Last Name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_column="1" />
              <EditText
              android:width="100px"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
       </TableRow>
</TableLayout>
• If this presentation helped you, please visit
  our page facebook.com/baabtra and like it.
  Thanks in advance.

• www.baabtra.com | www.massbaab.com |ww
  w.baabte.com
Thank you
Contact Us

More Related Content

PPTX
REAL TIME MONITORING OF ELCTRO CARDIC SIGNALS USING ARDUINO
PPTX
PPTX
Social and phycological effect of social media
PPTX

Similar to Layouts in android (20)

DOCX
Layout
PPTX
Android Layout.pptx
PPTX
Android Layout
PDF
Android ui layout
PDF
Android Screen Containers & Layouts
PPTX
Android Training (Android UI)
PPTX
Lecture_On_AndroidApp_UserInterface.pptx
PDF
Android UI Development
PPTX
Android development session 3 - layout
PPT
View groups containers
DOCX
Android practice of layout in application-chapter6
PPT
android layouts
PDF
01 08 - graphical user interface - layouts
PPTX
W1_Lec01_Lec02_Layouts.pptx
PDF
Ap quiz app
PDF
MOBILE APPLICATION DEVELOPMENT
PPTX
03 layouts & ui design - Android
PDF
Android UI Fundamentals part 1
PPTX
Android programming basics
PPTX
UNIT5newpart2pptx__2024_11_13_09_52_11 (1).pptx
Layout
Android Layout.pptx
Android Layout
Android ui layout
Android Screen Containers & Layouts
Android Training (Android UI)
Lecture_On_AndroidApp_UserInterface.pptx
Android UI Development
Android development session 3 - layout
View groups containers
Android practice of layout in application-chapter6
android layouts
01 08 - graphical user interface - layouts
W1_Lec01_Lec02_Layouts.pptx
Ap quiz app
MOBILE APPLICATION DEVELOPMENT
03 layouts & ui design - Android
Android UI Fundamentals part 1
Android programming basics
UNIT5newpart2pptx__2024_11_13_09_52_11 (1).pptx
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server
Ad

Layouts in android

  • 2. Disclaimer:This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. LAYOUTS IN ANDROID Ashwin Anand V Email:ashwinanand99@gmail.com Facebook id:ashwinanand99@gmail.com
  • 4. Android Layout • An Android layout is a class that handles arranging the way its children appear on the screen. Anything that is a View can be a child of a layout. • The standard layouts are,  Linear  Absolute  Relative  Frame  Table
  • 5. Absolute Layout Absolute Layout is based on the simple idea of placing each control at an absolute position.  Specify the exact x and y coordinates on the screen for each control  It was used rarely because it makes inflexibilities so very risk to maintain
  • 6. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_x="10px" android:layout_y="5px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_x="10px" android:layout_y="110px" android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_x="150px" android:layout_y="100px" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_x="10px" android:layout_y="160px" android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_x="150px" android:layout_y="150px" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> screenshot of the layout </AbsoluteLayout>
  • 7. Frame Layout  Frame Layout is designed to display a single item at a time  You can have multiple elements within a Frame Layout but each element will be positioned based on the top left of the screen.  Frame Layout can become more useful when elements are hidden and displayed programmatically. You can use the attribute android:visibility in the XML to hide specific elements
  • 8. <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android. com/apk/res/android"> <ImageView android:src="@drawable/icon" android:scaleType="fitCenter" android:layout_height="fill_parent" android:layout_width="fill_parent"/> <TextView android:text="Learn-Android.com" android:textSize="24sp" android:textColor="#000000" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center"/> </FrameLayout> screenshot of the layout
  • 9. Linear Layout Linear Layout organizes elements along a single line. You specify whether that line is vertical or horizontal using android:orientation. Here is a sample Layout XML using Linear Layout.
  • 10. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> screenshot of the layout
  • 11. Relative Layout Relative Layout lays out elements based on their relationships with one another, and with the parent container. This is arguably the most complicated layout, and we need several properties to actually get the layout we want.
  • 12. Relative To Container These properties will layout elements relative to the parent 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
  • 13. Relative To Other Elements • 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 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 • android:layout_alignTop – Places top of the new element in alignment with the top of the specified element
  • 14. <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://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:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/backbutton" /> <EditText android:id="@+id/editFirstName" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/firstName" android:layout_below="@id/backbutton"/> <EditText android:id="@+id/editLastName" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editFirstName" android:layout_alignLeft="@id/editFirstName"/> <TextView android:id="@+id/lastName" android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/editLastName" android:layout_below="@id/editFirstName" /> </RelativeLayout>
  • 15. Table Layout Table Layout organizes content into rows and columns. The rows are defined in the layout XML, and the columns are determined automatically by Android. This is done by creating at least one column for each element. You can specify that an element should occupy more than one column using android:layout_span. This can increase the total column count as well, so if we have a row with two elements and each element has android:layout_span=”3″ then you will have at least six columns in your table.
  • 16. <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/an droid"> <TableRow> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow> <TextView android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" /> <EditText android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow> <TextView android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" /> <EditText android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> </TableLayout>
  • 17. • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. • www.baabtra.com | www.massbaab.com |ww w.baabte.com