views:

21

answers:

0

I have a button. The button is constructed from the StateListDrawable (made of 3 9-patch images). I need to add an extra drawable that will reside on the button's right side, and i need it to be aligned with the button's right side. I tried to use the following:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <item android:drawable="@drawable/blue_back_button_drawable" />
    <item>
      <bitmap android:src="@drawable/filter_by_button_v_mark" android:gravity="right"/>
    </item>
</layer-list>

it didn't work and the V image is indeed aligned right but it has a diff from the button's right side. here's a snapshot: alt text

I want the image to be aligned with the button's left, the only way right now i think i can do it is:

  1. inherit button, in onLayout AFTER the width has been set get the right edge.
  2. get the background drawable (layerDrawable)
  3. calc the button's width minus the v image width and set it as left margin in the drawable.

I should not mention this sounds horrid :-) i hoped there's a better way. Oh the reason it's not part of the image is that i need to know it's width so i can calc the text padding so it wont be hidden by the button's text and because it's not so nice looking as a 9-patch.