You are on page 1of 11

8/28/23, 11:52 AM How to Draw Different Types of Circles in Android?

- GeeksforGeeks

How to Draw Different Types of Circles in Android?


aashaypawar

Read Discuss Courses Practice

In Android, we can manually create shapes as required. A shape can be designed in


XML by creating an Android Resource File. The type of file allows various attributes like
dimensions, color, strokes (border), solid (background), etc. for creating a desired shape
and design. Basically, in this article, we have explained 3 types of circles:

1. Circle 1: A simple circle with only a border


2. Circle 2: A simple circle with only solid color
3. Circle 3: A circle with a border and a solid color.

In this article, we will show you how you could create different types of circles. Now to
start with, follow the below steps once the IDE is ready.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge Got It !
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 1/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Complete Interview Preparation - Self Paced


A LIVE course designed for aspiring SDEs looking to switch to top
product-based companies. Mentored by industry

130+ hours 523k+ views

Certification Program LEARN MORE

To create a new project in Android Studio please refer to How to Create/Start a New
Project in Android Studio. We demonstrated the application in Kotlin, so make sure you
select Kotlin as the primary language while creating a New Project.

Step 2: Creating Android Resource Files

In this article, we shall be implementing 3 types of Circles. So we created three such


resource files for circle 1, circle 2, and circle 3. To create an Android Resource File, right-
click on the res folder, go to New and click on Android Resource File as shown below.

Name the file according to the circle. For the first file, we named it circle_1.

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

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 2/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Code for circle_1.xml:

Circle 1 is a simple circle that has nobody color and only an outline. For the same, the
code is given below.

XML

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<stroke
android:width="5sp"
android:color="#0f9d58"/>

</shape>

Sale Ends In 09 : 37 : 26 Data Types Array String Functions Collections Oops Android Android Studio Kotlin And

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

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 3/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Free training. Ask us how

Rubber Mold Company Open

Code for circle_2.xml:

In Circle 2, we have attributed it with only body color. Refer to the code below.

XML

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid
android:color="#0f9d58"/>

</shape>

Code for circle_3.xml:

In this circle, we have combined the above two attributes, i.e., boundary color and body
color. The code for the same is given below.
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

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 4/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

XML

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid
android:color="#0f9d58"/>

<stroke
android:width="5sp"
android:color="@color/black"/>

</shape>

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that
file. Below is the code for the activity_main.xml file. We shall be displaying all three
circles for which we need to add three ImageViews.

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">

<ImageView
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
android:id="@+id/circle_1"
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 5/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

android:layout_width="100sp"
android:layout_height="100sp"
android:src="@drawable/circle_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30sp"/>

<ImageView
android:id="@+id/circle_2"
android:layout_below="@id/circle_1"
android:layout_width="100sp"
android:layout_height="100sp"
android:src="@drawable/circle_2"
android:layout_centerHorizontal="true"
android:layout_marginTop="30sp"/>

<ImageView
android:id="@+id/circle_3"
android:layout_below="@id/circle_2"
android:layout_width="100sp"
android:layout_height="100sp"
android:src="@drawable/circle_3"
android:layout_centerHorizontal="true"
android:layout_marginTop="30sp"/>

</RelativeLayout>

No changes in MainActivity.kt. As we are displaying the circles directly into the


ImageViews, we shall leave the main file untouched.

Kotlin

package org.geeksforgeeks.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}

Output:

You can see the three types of circles that we created previously. Circle 1 has only
boundary color, Circle 2 has only body color, and Circle 3 has both boundary and body
color.
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

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 6/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Last Updated : 23 Jan, 2022

Similar Reads
Different Types of Act ivit ies in What Are t he Different Types of
Android St udio Bars Available in Android?

How to Use Different Types of Implement Different Types of


Google Maps in Android? Alert Box using Alerter Library in
Android

Android Jet pack Compose - Create Different Types of Circle in


Implement Different Types of Canvas in Android using Jet pack
St yles and Customizat ion to Text Compose

Detect Different Types of Touch How to Use Different Types of


Gest ures in Android using Jet pack Google Maps in Android using
Compose Jet pack Compose?

How to draw Horizontal and How to Draw Polyline in Google


Vert ical lines in an Android App Maps in Android?
using XML

Previous Next

OkHtt p Interceptor in Android How Room Works Internally in Android?

Article Contributed By :

aashaypawar
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
aashaypawar
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 7/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Vote for difficulty

Easy Normal Medium Hard Expert

Art icle Tags : Android, Kot lin


Pract ice Tags : Android

Improve Article Report Issue

Complete Interview Preparation - Self


Paced
A LIVE course designed for aspiring SDEs looking to switch
to top product-based companies. Mentored by industry

130+ hours 523k+ views

Certification Program LEARN MORE

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

feedback@geeksforgeeks.org

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
We use cookies to ensure youAdvertise withbrowsing
have the best us Master System Design
experience on our website. By using our site, you acknowledge
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 8/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Master CP

Languages DSA Concept s


Python Data Structures
Java Arrays
C++ Strings
PHP Linked List
GoLang Algorithms
SQL Searching
R Language Sorting
Android Tutorial Mathematical
Dynamic Programming

DSA Roadmaps Web Development


DSA for Beginners HTML
Basic DSA Coding Problems CSS
Complete Roadmap To Learn DSA JavaScript
DSA for FrontEnd Developers Bootstrap
DSA with JavaScript ReactJS
Top 100 DSA Interview Problems AngularJS
NodeJS
Express.js
Lodash

Comput er Science Pyt hon


GATE CS Notes Python Programming Examples
Operating Systems Django Tutorial
Computer Network Python Projects
Database Management System Python Tkinter
Software Engineering OpenCV Python Tutorial
Digital Logic Design Python Interview Question
Engineering Maths

Data Science & ML DevOps


Data Science With Python Git
Data Science For Beginner AWS
Machine Learning Tutorial Docker
Maths
We use cookies to ensure For Machine
you have Learningexperience on our website. By using our site, you acknowledge
the best browsing Kubernetes
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 9/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

Pandas Tutorial Azure


NumPy Tutorial GCP
NLP Tutorial
Deep Learning Tutorial

Compet it ive Programming Syst em Design


Top DSA for CP What is System Design
Top 50 Tree Problems Monolithic and Distributed SD
Top 50 Graph Problems Scalability in SD
Top 50 Array Problems Databases in SD
Top 50 String Problems High Level Design or HLD
Top 50 DP Problems Low Level Design or LLD
Top 15 Websites for CP Top SD Interview Questions

Int erview Corner Gf G School


Company Wise Preparation CBSE Notes for Class 8
Preparation for SDE CBSE Notes for Class 9
Experienced Interviews CBSE Notes for Class 10
Internship Interviews CBSE Notes for Class 11
Competitive Programming CBSE Notes for Class 12
Aptitude Preparation English Grammar

Commerce UPSC
Accountancy Polity Notes
Business Studies Geography Notes
Economics History Notes
Management Science and Technology Notes
Income Tax Economics Notes
Finance Important Topics in Ethics
UPSC Previous Year Papers

SSC/ BANKING Writ e & Earn


SSC CGL Syllabus Write an Article
SBI PO Syllabus Improve an Article
SBI Clerk Syllabus Pick Topics to Write
IBPS PO Syllabus Write Interview Experience
IBPS Clerk Syllabus Internships
Aptitude
We use cookies to ensure you have theQuestions
best browsing experience on our website. By using our site, you acknowledge
that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 10/11
8/28/23, 11:52 AM How to Draw Different Types of Circles in Android? - GeeksforGeeks

SSC CGL Practice Papers

@geeksforgeeks , Some 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

https://www.geeksforgeeks.org/how-to-draw-different-types-of-circles-in-android/ 11/11

You might also like