Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransitionDrawable with nine patches - margin is wrong

I have a TransitionDrawable. The two states are both nine patches and have a content area defined. The problem is the margin is just way too high - in fact it's basically twice as much as it should be. It seems like it's adding up the margins of the two nine patches.

The margin works as it's supposed to work if I set one of those ninepatches directly as a background and not use the TransitionDrawable, so the nine patch is definitely correct.

Has anybody encountered a problem like this?

EDIT: If I set the content area to the full size of the asset and define the padding in xml it works. OTherwise it'll always get the margin wrong. It seems like a bug in Android, so that seems to be the only solution, but maybe there's a nicer way to work around this :/

like image 912
Maria Neumayer Avatar asked Oct 21 '22 17:10

Maria Neumayer


1 Answers

Yep, you're right. Annoying indeed.

As you've proposed, I use the hard-coded negative paddings to compensate first_nine_patch's 9-patch padding so far.

<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/first_nine_patch" />
    <item android:drawable="@drawable/second_nine_patch"
        android:top="-7dp"
        android:right="-16dp"
        android:bottom="-8dp"
        android:left="-4dp" >
    </item>
</transition>
like image 58
riwnodennyk Avatar answered Nov 04 '22 20:11

riwnodennyk