I'm able to draw border to a linear layout, but it is getting drawn on all sides. I want to restrict it to right side only, like you do in CSS (border-right:1px solid red;).
I've tried this, but it still draws on all sides:
<?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="0dp"
android:left="0dp"
android:right="1dp"
android:top="0dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="5dp"
android:radius="1dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
Any suggestions on how to accomplish this?
BTW, I do not want to use the hack of putting a view of width 1dp on the required side.
As an alternative (if you don't want to use background), you can easily do it by making a view as follows:
For having a right border only, place this after the layout (where you want to have the border):
For having a left border only, place this before the layout (where you want to have the border):
Worked for me...Hope its of some help....
I was able to achieve the effect with the following code
You can adjust to your needs for border position by changing the direction of displacement
You can use this to get border on one side
EDITED
As many including me wanted to have a one side border with transparent background, I have implemented a
BorderDrawable
which could give me borders with different size and color in the same way as we use css. But this could not be used via xml. For supporting XML, I have added aBorderFrameLayout
in which your layout can be wrapped.See my github for the complete source.
it is also possible to implement what you want using a single layer
this way only left border is visible but you can achieve any combination you want by playing with
bottom
,left
,right
andtop
attributes of theitem
element