0

I am having trouble figuring out how to add a circle to a square shape in xml.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#00000000" />
<stroke android:width="2dip" android:color="#E68C7C"/>
<padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

I am setting the above xml as the background to a textview. That part works fine. I am trying to draw a circle in the bottom right corner of the the square as shown below.

circle button bottom right

Bryan Williams
  • 693
  • 1
  • 10
  • 27
  • Try using the `layer-list` options and creating two layers one of which is a rectangle while the other is a `android:shape ="oval"` and set params to the second shape to give it the red color – Android2390 Oct 28 '13 at 20:15
  • http://stackoverflow.com/questions/4146795/android-how-can-i-use-the-layer-list-and-shape-elements-to-draw-a-horizontal-ru – Android2390 Oct 28 '13 at 20:16
  • How do I go about making the circle be in the bottom right corner? What I'm getting is a square with a slightly smaller circle in it. – Bryan Williams Oct 28 '13 at 20:32
  • You can try offsetting with ``, etc as mentioned [here](http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList), but you'll probably have issues with scaling. Honestly, this looks like it would be roughly 98.3% easier with a 9patch background. – Geobits Oct 29 '13 at 01:46

1 Answers1

1

Please try below code:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:bottom="20dp"
        android:right="20dp">
        <shape
            android:shape="rectangle">
            <stroke android:width="1dp" android:color="#E68C7C" />
            <solid android:color="#00FF0000" />
            <padding android:bottom="1dp"/>
            <size android:width="100dp"
                android:height="100dp"/>
        </shape>
    </item>
    <item android:left="90dp"
        android:top="90dp"
        android:bottom="15dp"
        android:right="15dp">
        <shape
            android:shape="oval">
            <stroke android:width="1dp" android:color="#FF0000" />
            <solid android:color="#FF0000" />
            <size android:width="2dp"
                android:height="2dp"/>
        </shape>
    </item>

</layer-list>

The output of above code is:

enter image description here

I hope its work for you.

Android Geek
  • 8,956
  • 2
  • 21
  • 35