0

I am trying to make a imageview Rounded corners


  • I am trying to set it through XML and not programatically !
  • I have set background for my reference

Is it not possible to to set round corners through xml & we have to use bitmap ?


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_cornered_imageview"
            android:src="@drawable/image" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My-Text"
            android:textColor="@color/textbody"
            android:layout_gravity="bottom|center"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button1"
            android:layout_width="108dp"
            android:layout_height="74dp"
            android:background="@color/textbody"
            android:layout_gravity="top|center"
            android:text="Button" />

    </FrameLayout>

</LinearLayout>

OUTPUT

enter image description here

What i have tried ::

rounded_cornered_imageview.xml

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

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


        <corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" 
         android:topLeftRadius="10dp" android:topRightRadius="10dp"/>

          <stroke
            android:color="@color/black"
            android:width="1dp"

             />

    </shape>

But its not working ... where i need to correct myself ?

smriti3
  • 871
  • 2
  • 15
  • 35
  • possible duplicate of [How to make an ImageView to have rounded corners](http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners) – Benoit Jadinon Oct 27 '13 at 06:54
  • working fine at my end. – Jitender Dev Oct 27 '13 at 06:58
  • But since i have a background image .... is it behaving like that in my output ? – smriti3 Oct 27 '13 at 07:01
  • 1
    check this link http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ – Raghunandan Oct 27 '13 at 07:16
  • 1
    here's another http://stackoverflow.com/questions/16695023/how-to-create-a-background-with-image-rounded-corners-without-borders/16695407#16695407 – Raghunandan Oct 27 '13 at 07:18
  • @ Raghunandan ..... so when we have a background in imageview .... in order to get rounded corners .... we need to do it programatically and not with xml PS:: thanks for the links – smriti3 Oct 27 '13 at 07:22

1 Answers1

1

you can follow this below: on your gradle in dependencies

implementation 'com.makeramen:roundedimageview:2.3.0'

on your xml file

<com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/img_home_assistance"
        android:layout_width="match_parent"
        android:layout_height="123dp"
        app:riv_corner_radius="@dimen/padding_margin_15"
        android:layout_marginTop="6.8dp"
        android:layout_marginLeft="7.3dp"
        android:layout_marginRight="7.5dp"
        android:src="@drawable/migrate"
        android:scaleType="centerCrop"/>
CleanCoder
  • 332
  • 3
  • 14