1

I want to do this so I can change the margin within an animation-list.

This would move the button closer or further from the edge of the screen.

Jeremy
  • 3,620
  • 9
  • 43
  • 75

5 Answers5

18

You can simply use an InsetDrawable. This drawable simply adds an empty margin around any other drawable you want.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
1

This isn't possible but it's easy to create an animation like so

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

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromYDelta="0" android:toYDelta="100%" />
</set>

and then simply add the animation to the object and start it.

Jeremy
  • 3,620
  • 9
  • 43
  • 75
0

Well not exactly ., but you can use stroke tag with a transperent background.. but it ll give you uniform margin around the item

<item android:drawable="@drawable/blue" android:state_pressed="false"><shape>
        <solid android:color="#00000000" />

        <stroke android:width="1dp" android:color="#33B5E5" />

    </shape></item>

Chet
  • 1,205
  • 1
  • 12
  • 20
0

If your drawable is PNG, then It's simple, just add 1 transparent pixel around your drawable for every 1 pixel margin. but in this way you can not use dp unit, just pixels are accounted.

yrajabi
  • 637
  • 1
  • 9
  • 28
0

you can set a margin between content and a margin drawable with android:drawablePadding

Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34