BryanT
BryanT

Reputation: 412

How to use border (drawable) in a relative layout?

I have a drawable (xml) like this.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp"/>
<solid android:color="#FF00FF00"/>
</shape>

My button is within a parent linear layout.

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/custombordergreen"
    android:orientation="vertical">

    <Button
        android:id="@+id/startClock"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="204dp"
        android:layout_height="66dp"
         android:text="@string/start"
        android:textSize="22sp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/startbutton"/>

</LinearLayout>

But I can't use that technique if the button is already a sibling (and referenced in "toLeftOf") in a relative layout.

Short of re working the layout to avoid "relative", is there another way to put a border around my button?

Upvotes: 2

Views: 2247

Answers (2)

Pitty
Pitty

Reputation: 1997

Change your solid android:color in xml

<solid android:color="#00000000" />

Upvotes: 0

Gopal Singh
Gopal Singh

Reputation: 1133

put this as your button background

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

 <solid android:color="#ff3399" />

<stroke
    android:width="0.5dp"
    android:color="#111111" />

<corners
    android:bottomLeftRadius="05dp"
    android:bottomRightRadius="05dp"
    android:topLeftRadius="05dp"
    android:topRightRadius="05dp" />
</shape>

Upvotes: 5

Related Questions