scrolling grid (rows & columns) and the grid items are not necessarily predetermined but they automa cally inserted to the layout using a ListAdapter • An adapter actually bridges between UI components and the data source that fill data into UI Component. Adapter can be used to supply the data to like spinner, list view, grid view etc. • The ListView and GridView are subclasses of AdapterView and they can be populated by binding them to an Adapter, which retrieves data from an external source and creates a View that represents each data entry. GridView A ributes • android:id • This is the ID which uniquely iden fies the layout. • android:columnWidth • This specifies the fixed width for each column. This could be in px, dp, sp, in, or mm. • android:gravity • Specifies the gravity within each cell. Possible values are top, bo om, le , right, center, center_ver cal, center_horizontal etc. • android:horizontalSpacing • Defines the default horizontal spacing between columns. This could be in px, dp, sp, in, or mm. • android:numColumns • Defines how many columns to show. May be an integer value, such as "100" or auto_fit which means display as many columns as possible to fill the available space. • android:stretchMode • Defines how columns should stretch to fill the available empty space, if any. This must be either of the values − • none − Stretching is disabled. • spacingWidth − The spacing between each column is stretched. • columnWidth − Each column is stretched equally. • spacingWidthUniform − The spacing between each column is uniformly stretched.. • android:ver calSpacing • Defines the default ver cal spacing between rows. This could be in px, dp, sp, in, or mm. MainAc vity.java. • package com.example.helloworld; • import android.os.Bundle; • import android.app.Ac vity; • import android.view.Menu; • import android.widget.GridView; • public class MainAc vity extends Ac vity • { • @Override protected void onCreate(Bundle savedInstanceState) • { • super.onCreate(savedInstanceState); setContentView(R.layout. ac vity_main); • } • } ac vity_main.xml • <?xml version="1.0" encoding="u -8"?> • <androidx.constraintlayout.widget.ConstraintLayout xmlns: android="h p://schemas.android.com/apk/res/android" • <b> </b>xmlns:tools="h p://schemas.android.com/tools" • <b> </b>android:layout_width="match_parent" • <b> </b>android:layout_height="match_parent" • <b> </b>tools:context=".MainAc vity"> • <GridLayout • android:id="@+id/GridLayout1" • android:layout_width="match_parent" • android:layout_height="match_parent" • android:columnCount="2" • android:orienta on="horizontal" • android:rowCount="4" • tools:context=".GridXMLAc vity" • tools:layout_editor_absoluteX="56dp" • tools:layout_editor_absoluteY="0dp"> • <ImageBu on • android:id="@+id/imageBu on1" • android:layout_width="160dp" • android:layout_height="90dp" • android:layout_gravity="le |top" • android:src="@drawable/scene1" /> • <ImageBu on • android:id="@+id/imageBu on2" • android:layout_width="160dp" • android:layout_height="90dp" • android:layout_gravity="le |top" • android:src="@drawable/scene2" /> • <ImageBu on • android:id="@+id/imageBu on3" • android:layout_width="160dp" • android:layout_height="90dp" • android:src="@drawable/scene3" /> • <ImageBu on • android:id="@+id/imageBu on4" • android:layout_width="160dp" • android:layout_height="90dp" • android:layout_gravity="le |top" • android:src="@drawable/scene4" /> • <ImageBu on • android:id="@+id/imageBu on5" • android:layout_width="160dp" • android:layout_height="90dp" • android:layout_gravity="le |top" • android:src="@drawable/scene5" /> • <ImageBu on • android:id="@+id/imageBu on6" • android:layout_width="160dp" • android:layout_height="90dp" • android:layout_gravity="le |top" • android:src="@drawable/scene6" /> • </GridLayout> • </androidx.constraintlayout.widget.ConstraintLayout>