<size> attribute not useful when using layer-list?

Viewed 20275

Given I have a background drawable to create bulletpoints for TextViews like this:

Example of what I want

Then my XML code looks like this:

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

<layer-list
        xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:right="235dp">
        <shape android:shape="oval">
            <padding android:left="10dp" />
            <size android:height="5dp" android:width="5dp"/>
            <solid android:color="@color/my_pink"/>
        </shape>
    </item>
    <item android:left="10dp">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff"/>
            <padding android:left="10dp" />
        </shape>
    </item>
</layer-list>

But once I use the code shown above, my bullet points look like this:

Result of the XML shown above

It seems the <size> tag is ignored completely.

How would you solve this problem? Using a 9patch, yes I know.. perhaps that's the easiest to do.. but in fact I was hoping to find a XML solution as it's more flexible in the future.

Custom drawing is also out of the question.

2 Answers

<size> tag certainly works in layer-list and to show the bullet points for textviews you can use the xml attribute android:drawableLeft -> link

With this approach, there is no need of 9-patch and custom drawing.

Posting code & screenshot here for the reference.

res/drawable/bullet_point_layer.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="3dp">
    <shape android:shape="oval">
        <padding android:left="10dp" />
        <size android:height="10dp" android:width="10dp"/>
        <solid android:color="#ff0080"/>
    </shape>
</item>

res/layout/main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView one"
    android:textColor="@android:color/black"
    android:drawableLeft="@drawable/bullet_point_layer"
    android:background="@android:color/white" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView Two"
    android:textColor="@android:color/black"
    android:drawableLeft="@drawable/bullet_point_layer"
    android:background="@android:color/white" />

</LinearLayout> 

How it looks

Related