0

I'm using Imageview to show images and I"m using background drawable shape xml to show the image in circular shape.

It works fine when I preload the image, but I have set Onclick listener where user can edit and change user profile picture but when user selects image then it show rectunglar imageview instead of circulr.

How can I fixed it..

Here is the xml code

 <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/itemImage1"
                android:background="@drawable/shape"
                android:layout_marginLeft="5dp"
                android:layout_marginBottom="20dp"
                android:src="@android:drawable/ic_menu_camera"
                android:cropToPadding="true"
                android:scaleType="fitXY" />
and background shape xml file is

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

    <solid
        android:color="@color/white">
    </solid>

    <corners
        android:radius="7dp"   >
    </corners>


</shape>

Thanks in advance.

Pro Academy
  • 191
  • 1
  • 2
  • 12
  • check [this](https://stackoverflow.com/questions/16589110/set-a-drawable-as-background-programmatically) – nfl-x Aug 08 '19 at 22:56

2 Answers2

0

You can use this library.ı can use this for circle ımage view.İt is easy.

    <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/civProfilPicture"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:background="@drawable/ic_camera"

                            />

source:https://github.com/hdodenhof/CircleImageView

  • But I want the camera icon at left, so that user would know that they can edit images from icon. is there any such property here? – Pro Academy Aug 08 '19 at 15:20
  • that library will keep the image circular, its what it does @ProAcademy ive used it before for this purpose, works great. treat it as a normal imageview... – letsCode Aug 08 '19 at 15:34
  • @ProAcademy You can use it in FrameLayout.you can circle ımage view at bottom and add edit icon on cirleımage. – Enes BAŞKAYA Aug 09 '19 at 06:37
0

I think you want like this.You can use FrameLayout

  <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_margin="@dimen/small_padding"
    android:orientation="horizontal">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/civProfilPicture"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="@dimen/small_padding"
        android:background="@drawable/ic_profil"
        />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp" 
        android:background="@drawable/ic_edit"

        />

</FrameLayout>