Complete Layouts With Attributes
Complete Layouts With Attributes
Definition:
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:
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:
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:
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">
</LinearLayout>
</ScrollView>