1

How would i create a ImageView with a border and round corners?

I want to corners of the ImageView to be round, i tried creating a shape drawable with a stroke and round corners as background drawable of the ImageView but that doesn't give the right effect, because the image is padded inside the container and does not fill out to the edge of the borders.

Cristian
  • 198,401
  • 62
  • 356
  • 264
Mads Lee Jensen
  • 4,570
  • 5
  • 36
  • 53

1 Answers1

1

i know this works on LinearLayout, but i'm not sure it works on imageviews , worth a try ,you could do something like this on the background

so your imageview would look something like this maybe

<ImageView android:background="@drawable/rounded"/>

if you call this file rounded.xml or something

<?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="@drawable/black"
            android:width="1dp"

             />

    </shape>

this page is a good reference http://developer.android.com/guide/topics/resources/drawable-resource.html

slim
  • 4,010
  • 9
  • 35
  • 42
  • 4
    I don't think this works on ImageView - BUT - you can just put your ImageView in such a linearlayout - that's what I do and it works well. +1 – shein Dec 16 '10 at 23:55
  • thats a great idea, might just work – slim Dec 17 '10 at 07:58
  • 5
    The problem is as i describe in my question, this will give a rectangle with round corners outside of the image. The image will still have the "sharp" corners and will not fill out to the edges of the border. – Mads Lee Jensen Dec 21 '10 at 08:25
  • of course there will be cases where this will not work, but in the instances where you can make the linearlayout color the same color as the image edges color, this fix requires very little except some xml layout, i understand it won't work in all cases – slim Dec 21 '10 at 18:27
  • 1
    I tried but does not work. – LiangWang Aug 07 '13 at 21:03