• Layouts are subclasses of the ViewGroup class.
  • 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 we can declare our layout using a simple XML file which is located in the res/layout folder of our project.
Layouts Types
  • There are several types of Layouts that will be used in almost all Android applications to provide a different view, look, and feel. These are:-
    • Linear Layout
      • LinearLayout is a view group that aligns or arranges all children in a single direction, vertically or horizontally.
    • Relative Layout
      • RelativeLayout is a view group that displays child views in relative positions i.e., Positions child views relative to each other or relative to the parent view..
    • Constraint Layout
      • Allows creating complex layouts by setting constraints between views, offering flexibility and responsiveness.
      • Android Constraint Layout is used to define a layout by assigning constraints for every child view/widget relative to other views present.
      • A Constraint Layout is similar to a relative layout but with more power.
      • The aim of Constraint Layout is to improve the performance of the applications by removing the nested views with a flat and flexible design.
      • A view inside the Constraint Layout has handles(or anchor points) on each side which are used to assign the constraints. 
    • Absolute Layout
        • Absolute Layout enables to specify the exact location of its child views.
    • Frame Layout
      • The Frame Layout is a placeholder on the screen that is used to display more than one view as a single view.
      • Places child views on top of each other, often used for simple container layouts.
    • List View
      • ListView is a viewgroup that displays a list of scrollable items.
    • Grid View
      • GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid.
    • Table Layout
      • TableLayout is a view that groups views into rows and columns.
Layouts Attributes
  • Each layout has a set of attributes that define the visual properties of that layout.
  • There are few common attributes among all the layouts and there are other attributes that are specific to that layout. These are –
    • android: id
      • This is the ID that uniquely identifies the view that is used in coding for calling or representing it.
    • android:layout_width
      • This attribute represents the width of the layout.
      • android:layout_width=wrap_content tells about the view occupying the size itself to the dimensions required by its content.
      • android:layout_width=fill_parent tells about the view to become as big as its parent view.
    • android:layout_height

      • This attribute represents the height of the layout
    • android:layout_marginTop
      • This attribute represents the extra space on the top side of the layout.
    • android:layout_marginBottom
      • This attribute represents the extra space on the bottom side of the layout.
    • android:layout_marginLeft
      • This attribute represents the extra space on the left side of the layout.
    • android:layout_marginRight
      • This attribute represents the extra space on the right side of the layout.
    • android:layout_gravity
      • This attribute represents how child Views are positioned either horizontally or vertically.
    • 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
      • This attribute represents the width of the layout.
    • android:padding-left
      • This attribute represents the left padding filled for the layout.
    • android:padding-right
      • This attribute represents the right padding filled for the layout.
    • android:paddingTop
      • This attribute represents the top padding filled for the layout.
    • android:padding-bottom
      • This attribute represents the bottom padding filled for the layout.
Units Used in Layouts Attributes
  • dp (Density-independent Pixels):
  • sp ( Scale-independent Pixels):
  • pt ( Points which is 1/72 of an inch):
  • px( Pixels):
  • mm ( Millimeters):
  • in (inches):


Categories: Android


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.