I want to use border image is below :
set border for Layout ...?
Should i do it ?
<?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>
Save this file in as customborder.xml in drawbale folder. In you layout file add this line android:background="#drawable/customborder"
You can make a 9-patch image as apply it as the background. Make the middle transparent and fill the border the way you want.
Here is the official documentation: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
What you can do is create an custom drawable shape that will apply as the background of ImageView which will create a border.
Something like below xml, you can customize it yourself. Put it in drawable/image_border.xml
<?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:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
Apply it as ImageView's background. It should create a border for your ImageView.
first create simple border.xml and save in to drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#00000000" />
<stroke android:width="2dp" android:color="#000000"/>
</shape>
</item>
</layer-list>
then after set background of Linear/Relative layout
android:background="#drawable/imageee_color"
Related
enter image description here
How to add this type of frame in android over an image like the picture given
If you are searching for custom border and shape of ImageView
Try this
or
set the below XML to the background of the Image View as Drawable. It works.
<?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 add android:background="#drawable/yourXmlFileName" to your ImageView
I want to add gradient only to the border of my editText , I can add gradient but it takes the entire background . How can I apply gradient only to the border , and the rest should be transparent?
This one does the trick :)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="45"
android:endColor="#0256FC"
android:centerColor="#0256FC"
android:startColor="#FE00B1" />
<corners android:radius="4dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<size
android:width="162dp"
android:height="44dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorWhite" />
<corners android:radius="4dp" />
<size
android:width="50dp"
android:height="50dp" />
</shape>
</item>
</layer-list>
Add the edittext in a layout
Set gradient background color for that layout
Set margin 1dp for edittext.
Set white background for edittext
i think now it's displays like your expectation, thank you
Create your button_border.xml and keep it within drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#color/white" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
Now set your editText background as follows :
android:background="#drawable/button_border"
I set the Root Layout background as black colour with corner radius and padding. I set the child layout background as white colour only so the corners seems to be removed. I mean it white colour as overlay of the black. I found one solution for this i.e., we should maintain one more xml like root layout background. Is there any good solution instead of this?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/black_color" />
<corners android:radius="10dp" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
You need to create another XML file for the white background and give corner top radius to left-right only. And apply this background to the child view.
try this or a modification of this.Just modify the lines and other things as you need it.I needed a black bar at the top.I just modified that to white for your use.But you will still ahve trim your image to be smaller than the overall border.
what if you put your image as
android:scaleX="0.95"
android:scaleY="0.95"
the drawable code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="40dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#7F7F7F" />
</shape>
</item>
<item android:top="40dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#7F7F7F" />
</shape>
</item>
<item
android:bottom="40dp"
android:left="1dp"
android:right="1dp"
android:top="24dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
I have create a shape.xml in android project. In this xml file i have a rectangle shape design with border.This is working fine. I need to create a another rectangle shape with left border in the same xml. Is this possible or not. If its possible means how can i refer the two diff shape in layout page.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:height="2dp"
android:width="2dp"
android:color="#FF0000" />
<solid android:color="#000000" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="5dp"
android:radius="1dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
http://stackoverflow.com/questions/4740538/can-i-use-multiple-shapes-in-one-android-drawable
http://stackoverflow.com/questions/5702143/multipe-shapes-inside-shapes-xml-in-android
<?xml version="1.0" encoding="utf-8"?>
<layer-list>
<item android:drawable="#drawable/shape_7"/>
<item android:drawable="#drawable/shape_1"/>
</layer-list>
I am trying to make a drawable to use for a button. I would like it to have this coloring, with a 2px border around it.
Everything works just fine except I cannot get the border to show up...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:startColor="#color/bar_clicked_dark"
android:endColor="#color/bar_clicked_light"
android:angle="90"/>
<corners android:bottomLeftRadius="0dp"
android:topLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topRightRadius="0dp" />
<stroke android:width="2dp"
color="#ff00ffff" />
</shape>
It looks like you forgot the prefix on the color attribute. Try
<stroke android:width="2dp" android:color="#ff00ffff"/>
If you want make a border in a shape xml. You need to use:
For the external border,you need to use:
<stroke/>
For the internal background,you need to use:
<solid/>
If you want to set corners,you need to use:
<corners/>
If you want a padding betwen border and the internal elements,you need to use:
<padding/>
Here is a shape xml example using the above items. It works for me
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#D0CFCC" />
<solid android:color="#F8F7F5" />
<corners android:radius="10dp" />
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
</shape>
We can add drawable .xml like below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/color_C4CDD5"/>
<corners android:radius="8dp"/>
<solid
android:color="#color/color_white"/>
</shape>