ImageView

ImageView

  • ImageView class is used to display any kind of image resource in the android application either it can be android.graphics.Bitmap or android.graphics.drawable.Drawable (it is a general abstraction for anything that can be drawn in Android). ImageView class or android.widget.ImageView inherits the android.view.View class which is the subclass of Kotlin. AnyClass.Application of ImageView is also in applying tints to an image in order to reuse a drawable resource and create overlays on background images. Moreover, ImageView is also used to control the size and movement of an image.
 

XML Attributes of ImageView

XML Attribute
Description
android:id
To uniquely identify an image view
android:src/app:srcCompat
To add the file path of the inserted image
android:background
To provide a background color to the inserted image
android:layout_width
To set the width of the image
android:layout_height
To set the height of the image
android:padding
To add padding to the image from the left, right, top, or bottom of the view
android:scaleType
To re-size the image or to move it in order to fix its size
 

Example:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ImageView android:id="@+id/GfG_full_logo" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.078" app:srcCompat="@drawable/full_logo" /> <ImageView android:id="@+id/GfG_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/GfG_full_logo" app:srcCompat="@drawable/logo" /> </androidx.constraintlayout.widget.ConstraintLayout>