Border for transparent image in android

I want an image that has only a border, and it is transparent inside. The usual trick for getting the border seems to be to use another image a little larger just below the image for which we want to get the border, but this will not work here because I need a transparent image. How can I create it?

+4
source share
2 answers

create a new backgroundcolor.xml file in a transfer 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 image

+11
source

You can use the xml file as a picture for the image. For example, put this xml file as border.xml in the 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 drop-down background for the image. The image will be blank and only the frame 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> 
0
source

Source: https://habr.com/ru/post/1438897/


All Articles