Open-Sided Android Stroke

Android: Stroke Left Side of Button Only

You can try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:bottom="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="@android:color/transparent" />

<stroke
android:width="1dp"
android:color="#FF8888" />
</shape>
</item>
<item
android:drawable="@drawable/shape2"
android:left="1dp">
</item>

</layer-list>

Where @drawable/shape2 is the shape you specified above

result:

Sample Image

How to draw border on just one side of a linear layout?

You can use this to get border on one side

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>

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 a BorderFrameLayout in which your layout can be wrapped.

See my github for the complete source.



Related Topics



Leave a reply



Submit