Following the question: Animate change of view background color on Android I am trying to make a TextView to fade between two backgrounds via TransitionDrawable resource. My transition xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/gray_bar" />
<item android:drawable="@drawable/green_bar" />
</transition>
And I try to set it as background on runtime by:
TextView answerBox = (TextView) findViewById(R.id.answerBox);
answerBox.setBackgroundResource(R.drawable.correct_transition);
TransitionDrawable transition = (TransitionDrawable) answerBox.getBackground();
transition.startTransition(1500);
The result is that the textview transforms from this:
to this:
When the whole gray bar should be transformed into the green one.
Both are 9-patch png images. These are the originals:
My guess is that the green bar is filling the space available for text inside the gray bar, but I don't know why. Any clues? The gray one also appears much bigger than it should, but does not change size before, during or after the transition, despite the appearance of the included images. It may be an issue with the 9-patch images cause I have tested normal images and the transition works great.
Thanks for any help!