Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android xml shape drawable - how to draw a u-form?

Tags:

android

xml

shape

I need to create a xml shape drawable that draws a rectangle without the top-line (a "u-form"). What I am able to do is draw a rectangle, like so:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/detailrow_bg_normal" />

<corners
    android:bottomLeftRadius="0dp"
    android:bottomRightRadius="0dp"
    android:radius="1dp"
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp" />

<padding
    android:bottom="2dip"
    android:left="1.5dip"
    android:right="1.5dip"
    android:top="8dip" />

<stroke
    android:width="1dip"
    android:color="@color/detailtable_border" />

But how - if possible, can I define the same shape without the top (or bottom) line?

like image 950
Bachi Avatar asked Apr 16 '12 17:04

Bachi


2 Answers

You could try using a layer-list. See if something like this would work:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape android:shape="rectangle">
            <solid android:color="@color/detailtable_border" />
        </shape>
   </item>

   <item android:left="1.5dp" android:right="1.5dp" android:bottom="2dp">
      <shape android:shape="rectangle">
        <solid android:color="@color/detailrow_bg_normal" />
      </shape>
   </item>
</layer-list>

This (should) fill the rectangle with the border color, then overlay it with the default background color, leaving the appropriate amount of the right/left/bottom border color showing.

like image 140
Femi Avatar answered Oct 22 '22 19:10

Femi


try this code and also refer this link:::

I achieved a good solution with this one:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
    <item android:top="-1dp" android:right="-1dp" android:left="-1dp">
      <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="#ffffff" />
      </shape>
    </item>

</layer-list>

This works well in case you need a transparent color but still an open stroke color (In my case i only needed a bottom line). If you need a background color you can add a solid shape color as in above answer.

like image 34
Shankar Agarwal Avatar answered Oct 22 '22 19:10

Shankar Agarwal