This article aims to help in how to make a circular image view on an image using the Android App. A simple circular image view can be made with white border and transparent content with shape without using any library.
Below are steps on how to do so:
- Step 1: Creating the layout of the circular image view
Create a new drawable resource file in the drawable directory which defines the shape of image view that is a circle.circular.xml
<?xmlversion="1.0"encoding="utf-8"?><!--res/drawable/circular.xml--><!--defines the circular shape and its properties-->android:innerRadius="0dp"android:shape="ring"android:thicknessRatio="2.0"android:useLevel="false"><solidandroid:color="@android:color/transparent"/><strokeandroid:width="9dp"android:color="@android:color/white"/></shape>chevron_rightfilter_none- Step 2: Next step is to make a layerlist drawable so that it can act as background to your imageview. Create a new XML file in drawable directory with name image.xml
image.xml
<?xmlversion="1.0"encoding="utf-8"?><!--res/drawable/image.xml--><!--define layer-list--><layer-list<!--set image to be shown on cicular image view--><itemandroid:drawable="@drawable/ic_launcher"/><itemandroid:drawable="@drawable/circular"/></layer-list>chevron_rightfilter_none- Step 3: Creating the activity_main.xml
activity_main.xml
<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"><!--put image.xml as background to your image view--><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/image"/></RelativeLayout>chevron_rightfilter_none- Step 4: Creating the backend MainActivity.java file
MainActivity.java
packagecom.geeksforgeeks.circularimageview;importandroid.support.v7.app.AppCompatActivity;importandroid.graphics.drawable.ColorDrawable;importjava.io.IOException;publicclassMainActivityextendsAppCompatActivity {ImageView imageView;@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ActionBar actionBar;actionBar = getSupportActionBar();ColorDrawable colorDrawable=newColorDrawable(Color.parseColor("#0F9D58"));actionBar.setBackgroundDrawable(colorDrawable);Toast.makeText(MainActivity.this,"Circular Image View "+"without using any library",Toast.LENGTH_LONG).show();}}chevron_rightfilter_noneOutput: Circular image view
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- How to Add OpenCV library into Android Application using Android Studio?
- How to create popup message using Alerter Library in android
- How to Create a CircularImageView in Android using hdodenhof Library?
- How to Create Circular ImageView in Android using CardView?
- Image loading and caching library for Android | Set 1
- Image loading and caching library for Android | Set 2
- How to install Android Applications in Mobile Phone without USB Cables using Android Studio
- Android | How to Create/Start a New Project in Android Studio?
- How to add Cutsom Switch using IconSwitch Library in android?
- How to Create a COVID-19 Tracker Android App to See Details of any City and State in India?
- Triple-Tap on a View Using onTouchListener Object in Android
- How to create a CalendarPickerView using TimeSquare library
- How to Create AlertDialog Box Using SweetAlert Dialog Library?
- Image Processing in Java | Set 3 (Colored image to greyscale image conversion)
- Image Processing in Java | Set 4 (Colored image to Negative image conversion)
- Image Processing in Java | Set 6 (Colored image to Sepia image conversion)
- Volley Library in Android
- How to add Slidr Library in Android?
- Android | Creating a Calendar View app
- How to implement View Shaker in Android
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
- Step 2: Next step is to make a layerlist drawable so that it can act as background to your imageview. Create a new XML file in drawable directory with name image.xml


