Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Create Circular ImageView in Android using CardView?
Next article icon

How to Create Circular ImageView in Android using CardView?

Last Updated : 15 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Displaying an Image in Android is done easily using ImageView. But what if one wants to display a circular image? It is seen that many Android apps use CircularImageView to show the profile images, status, stories, and many other things but doing this with a normal ImageView is a bit difficult. This article will help to create a circular image using CardView. Through cardCornerRadius one can customize the corner of the ImageView. A sample image is given below to get an idea about what we are going to create in this article. We are going to implement this project using both Java and Kotlin Programming Language for Android.

Circular ImageView Example
 

Note: One may perform the same operation in another two methods. Please refer to the link below:

  • How to create a Circular image view in Android without using any library?
  • How to Create a CircularImageView in Android using hdodenhof Library?

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.

Step 2: Adding Dependency to the build.gradle File

 Go to Module build.gradle file and add this dependency and click on Sync Now button.

implementation 'androidx.cardview:cardview:1.0.0'

Step 3: Working with the XML Files

Next, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

Note: Change android:src="@drawable/your_image" to your Image Name
XML
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout     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">      <!-- Using CardView for CircularImageView -->     <androidx.cardview.widget.CardView         android:id="@+id/cardView"         android:layout_width="200dp"         android:layout_height="200dp"         android:layout_centerHorizontal="true"         android:layout_marginTop="150dp"         app:cardCornerRadius="100dp">          <!-- add a Image image.png in your Drawable folder -->         <ImageView             android:id="@+id/imageView"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:scaleType="centerCrop"             android:src="@drawable/circular" />     </androidx.cardview.widget.CardView>      <TextView         android:id="@+id/textView"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/cardView"         android:layout_marginTop="25dp"         android:gravity="center"         android:text="Circular ImageView"         android:textColor="@color/colorPrimary"         android:textSize="20sp"         android:textStyle="bold" /> </RelativeLayout> 

Step 4: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.

Java
import android.os.Bundle; import android.widget.ImageView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity;  public class MainActivity extends AppCompatActivity {      ImageView imageView;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          imageView = findViewById(R.id.imageView);                  imageView.setOnClickListener(v ->              Toast.makeText(MainActivity.this, "This is a Circular ImageView", Toast.LENGTH_SHORT).show()         );     } } 
Kotlin
import android.os.Bundle import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity  class MainActivity : AppCompatActivity() {          private lateinit var imageView: ImageView          override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)                  imageView = findViewById(R.id.imageView)                  imageView.setOnClickListener {             Toast.makeText(this, "This is a Circular ImageView", Toast.LENGTH_SHORT).show()         }     } } 

Output:

Circular ImageView Example Output
 

Next Article
How to Create Circular ImageView in Android using CardView?

Y

yashwanthmy
Improve
Article Tags :
  • Java
  • Kotlin
  • Android
  • Android-View
Practice Tags :
  • Java

Similar Reads

    Circular ImageView in Android using Jetpack Compose
    Circular ImageView is used in many of the apps. These types of images are generally used to represent the profile picture of the user and many more images. We have seen the implementation of ImageView in Android using Jetpack Compose. In this article, we will take a look at the implementation of Cir
    2 min read
    How to Create CircularDialog in Android?
    CircularDialog is another best way of representing information or data in an Android app. You can get to see these Circular Dialogs in most of the apps which are used to display the message of completion of the process in an attractive form. In this article, we are going to see how to implement Circ
    3 min read
    How to Make CardView Checkable In Android?
    In Android, We can make a CardView checkable, which can be really a useful feature. If we want the user to select some items and want to display the items that the user has chosen then this one is the most important feature for us. A sample GIF is given below to get an idea about what we are going t
    4 min read
    How to Create an Expandable CardView in Android?
    Expandable Cardview provides to create expansion panels without too much hassle and without writing boilerplate code. An expandable card view becomes quite useful when it comes to an efficient and systematic presentation of data or information on the screen. It is used in a variety of apps, for exam
    5 min read
    How to Add Gradient to CardView in Android?
    UI stands for User Interface, which represents the graphical interface that allows the user to interact with software or any other devices. It comprises some visual elements like Buttons, icons, text, and Images that allow users to steer and interact with the software. UI basically concentrate on cr
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences