Reputation: 9634
I have listview and i have got set of images in a row. I would like to add border for images what is the simplest way.
Upvotes: 2
Views: 357
Reputation: 66
I got your Question Now If you have ImageView in Your XML file then you also have this below code:
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
So add below line in your imageView tag:
android:background="@drawable/Imagexml"
android:padding="6dp"
Now as in android:background there is Imagexml.xml file in drawable folder .
The Imagexml.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#0079AD"
android:endColor="#009AD6"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#F1FAFE" />
<corners
android:radius="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#007900"
android:startColor="#009A77"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#F1FAFE" />
<corners
android:radius="3dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#0079AD"
android:startColor="#009AD6"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#F1FAFE" />
<corners
android:radius="3dp" />
</shape>
</item>
</selector>
Then you will get the result as you want.
Upvotes: 0
Reputation: 2158
put this with in drawable folder with name image_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dip" android:color="#8d8d8d" />
<padding
android:left="1dip"
android:top="1dip"
android:right="1dip"
android:bottom="1dip" />
<solid android:color="#000000" />
<corners android:radius="10dip" />
</shape>
and use attributes android:background="@drawable/image_border"
for ImageView
You can change the shape according your requirement.
Upvotes: 2