Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I shape Circular the selected image from gallery

How to have a curcular ImageView. This is my xml

<RelativeLayout
            android:id="@+id/imgUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:background="@drawable/circle_border">

            <ImageView
                android:id="@+id/studentimg"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_margin="9dp"
                android:adjustViewBounds="true"
                android:background="@drawable/circlepf"
                android:padding="3dp"
                android:scaleType="centerInside"
                android:src="@drawable/ic_profile" />
</RelativeLayout>

this is my problem image sample

1

but I want this image to show in circular view

like image 403
Chudamani Meher Avatar asked Jan 15 '20 11:01

Chudamani Meher


People also ask

How do I make an image circular in Android?

Simply put a circular_crop. png in your drawable folder which is in the shape of your image dimensions (a square in my case) with a white background and a transparent circle in the center. You can use this image if you have want a square imageview.


1 Answers

You can use the Material Components Library.
With the version 1.2.0-alpha03 there is the new ShapeableImageView.

  <com.google.android.material.imageview.ShapeableImageView
      ...
      android:scaleType="centerInside"
      android:adjustViewBounds="true"
      app:shapeAppearanceOverlay="@style/circleImageView"
      app:srcCompat="@drawable/ic_profile" />

with:

  <style name="circleImageView" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">50%</item>
  </style>

enter image description here

like image 150
Gabriele Mariotti Avatar answered Sep 17 '22 16:09

Gabriele Mariotti