0% found this document useful (0 votes)
9 views4 pages

Complete Layouts With Attributes

The document provides an overview of various Android layout types including RelativeLayout, AbsoluteLayout, GridView, ImageView, and ScrollView, detailing their definitions, important attributes, and examples. RelativeLayout allows dynamic positioning of child views, while AbsoluteLayout is deprecated for responsive designs. GridView is used for displaying items in a grid, ImageView for displaying images, and ScrollView enables vertical scrolling for content that exceeds screen size.

Uploaded by

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

Complete Layouts With Attributes

The document provides an overview of various Android layout types including RelativeLayout, AbsoluteLayout, GridView, ImageView, and ScrollView, detailing their definitions, important attributes, and examples. RelativeLayout allows dynamic positioning of child views, while AbsoluteLayout is deprecated for responsive designs. GridView is used for displaying items in a grid, ImageView for displaying images, and ScrollView enables vertical scrolling for content that exceeds screen size.

Uploaded by

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

RelativeLayout

Definition:

 - Places child views relative to each other or to the parent.


 - Provides flexibility for complex UI arrangements.
 - Good for avoiding nested layouts by aligning views dynamically.

Important Attributes:

 - android:layout_alignParentTop/Bottom/Left/Right
 - android:layout_below/above
 - android:layout_toLeftOf/toRightOf
 - android:layout_centerInParent

Example:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_marginTop="10dp" />
</RelativeLayout>

AbsoluteLayout
Definition:

 - Positions views using exact X and Y coordinates.


 - Not recommended for responsive layouts (deprecated).
 - Use only for simple, fixed layouts where screen size doesn't vary.

Important Attributes:

 - android:layout_x
 - android:layout_y
 - android:layout_width
 - android:layout_height

Example:

<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="100dp"
android:text="Click Me"/>
</AbsoluteLayout>

GridView
Definition:

 - Displays items in a scrollable grid format.


 - Commonly used for image galleries or item selections.
 - Efficiently handles large sets of items using adapters.

Important Attributes:

 - android:numColumns
 - android:verticalSpacing
 - android:horizontalSpacing
 - android:stretchMode

Example:

<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" />

ImageView
Definition:
 - Displays images from resources or URLs.
 - Can be scaled or cropped using different scale types.
 - Useful for icons, logos, banners, and more.

Important Attributes:

 - android:src
 - android:scaleType
 - android:adjustViewBounds
 - android:contentDescription

Example:

<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/myimage"
android:scaleType="centerCrop" />

ScrollView
Definition:

 - Allows vertical scrolling for content that doesn't fit on screen.


 - Can contain only one direct child (usually a layout like LinearLayout).
 - Ideal for forms or long text content.

Important Attributes:

 - android:fillViewport
 - android:scrollbars
 - android:layout_height
 - android:layout_width

Example:

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView android:text="Item 1" />


<TextView android:text="Item 2" />
<!-- More items -->

</LinearLayout>
</ScrollView>

You might also like