0

I'm trying to create a ShapeDrawable for the background of my table cells. At the moment, I have a white rectangle with a 1px black border:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape= "rectangle"  >
    <solid android:color="#fff"/>
    <stroke android:width="1dp"  android:color="#000"/>
</shape>

I'd like to get this exact thing but with the border only along the top and bottom of the shape. Can someone show how to do this, or link to a page explaining how to use ShapeDrawable? Thanks!

Nat
  • 53
  • 1
  • 1
  • 6

1 Answers1

0

You use a layer-list take a look at this

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#FF0000" />
    </shape>
</item>
<item android:top="5dp" android:bottom="5dp">
    <shape android:shape="rectangle">
        <solid android:color="#000000" />
    </shape>
</item>

Or you may just do a padding on your layout like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:layout_marginTop="5dp"android:layout_marginBottom="5dp"></LinearLayout>

</LinearLayout>
Sheychan
  • 2,415
  • 14
  • 32