Christian Cederquist
Christian Cederquist

Reputation: 513

Create a drawable containing another drawable and a margin

Is there a way to create a drawable in xml, which uses an image and some margin to offset it? This is for adding a drawable to a place where you can't set the margin, i.e. when changing the 'up' caret of the action bar.

Upvotes: 3

Views: 4286

Answers (1)

Christian Cederquist
Christian Cederquist

Reputation: 513

Found out with a little searching on Android's developer page. You can create a layer-list, and in it have a single item:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item
      android:left="[margin in pixels(dp)]"
      android:drawable="@drawable/side_bar_button"/>
</layer-list>

This offsets the drawable to the left by the amount of pixels you'd like. This can also be done for right, top and bottom.

Upvotes: 11

Related Questions