Reputation: 8411
I want an imageview that only has border and it transparent inside.The common trick for getting border seems to be using another imageview of slightly greater size just below the imageView for which we want border but this won't work here because i want a transparent imageview. How can i create it ?
Upvotes: 4
Views: 4476
Reputation: 20553
You can use an xml file as a drawable for an imageview. For example, put this xml file as border.xml in your drawable-mdpi folder:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
and then in your main layout, use it as a drawable background for the imageview. THe imageview will be empty and only the border will be displayed.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:src="@drawable/border" />
</LinearLayout>
Upvotes: 0
Reputation: 513
create a new backgroundcolor.xml file in drawable folder
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/transparent" />
<stroke
android:width="0.5dip"
android:color="@color/black" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
and add this as a background to your imageview
Upvotes: 11