In Android, is it possible to set the margin from

2019-07-28 22:09发布

问题:

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.

回答1:

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



回答2:

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.



回答3:

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>



回答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.



回答5:

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