Skip to content Skip to sidebar Skip to footer

In Android, Is It Possible To Set The Margin From The Drawable?

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.

Solution 1:

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

Solution 2:

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

<?xml version="1.0" encoding="utf-8"?><setxmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"><translateandroid:fromYDelta="0"android:toYDelta="100%" /></set>

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

Solution 3:

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

<itemandroid:drawable="@drawable/blue"android:state_pressed="false"><shape><solidandroid:color="#00000000" /><strokeandroid:width="1dp"android:color="#33B5E5" /></shape></item>

Solution 4:

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.

Solution 5:

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

Post a Comment for "In Android, Is It Possible To Set The Margin From The Drawable?"