lecture 6
lecture 6
(Lecture-4)
• Layouts
• Linear Layout
• Relative Layout
• Frame Layout
• Constraint Layout
2
Definition of Layouts
• Layouts in Android refer to the structure that defines how UI elements,
such as buttons, text fields, images, and other views, are arranged and
displayed on the screen.
• Layouts are containers that hold views (UI components) and define the
spatial relationship between them.
• The layout dictates the position, size, and appearance of its child views on
different devices and screen sizes.
3
RelativeLayout
• Definition: Places child views relative to each other or the parent
container
• Common attributes:
• layout_alignParentTop =“true”: Aligns the top edge of the view to the top
edge of the parent (RelativeLayout).
• android:layout_alignParentBottom=“true”: Aligns the bottom edge of the
view to the bottom edge of the parent.
• android:layout_alignParentStart=“true”: Aligns the start edge (left for LTR,
right for RTL) of the view to the start edge of the parent.
4
• layout_alignParentEnd=“true”: Aligns the end edge (right for LTR, left for
RTL) of the view to the end edge of the parent.
• layout_centerInParent =“true”: Centers the view both vertically and
horizontally within the parent layout.
• layout_centerHorizontal =“true”: Centers the view horizontally within the
parent layout.
• layout_centerVertical =“true”: Centers the view vertically within the
parent layout.
• layout_above ="@id/textView1" : Positions the view directly above
another view.
5
• layout_below ="@id/textView1" : Positions the view directly below
another view.
6
FrameLayout Overview
• Definition: Simplest layout, designed to display one child view at a time
• Stacks multiple views on top of each other
• Common attributes:
• layout_gravity
• layout_width,
• layout_height
7
ConstraintLayout Overview
• Definition: Flexible layout that positions elements based on constraints
• More efficient for complex UIs
• Key attributes:
• layout_constraintStart_toStartOf
• layout_constraintTop_toTopOf
• layout_constraintBottom_toBottomOf
8
Comparison Table
9
Thank You…!