TransitionDrawable as background in TextView not working properly

Following the question: Animate the background color of a view on Android I'm trying to make a TextView disappear between two backgrounds through a TransitionDrawable resource. My transition XML file is as follows:

<?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'm trying to set it as background at runtime:

TextView answerBox = (TextView) findViewById(R.id.answerBox);
answerBox.setBackgroundResource(R.drawable.correct_transition);
TransitionDrawable transition = (TransitionDrawable) answerBox.getBackground();
transition.startTransition(1500);

As a result, the text is converted from this:

Textview with gray_bar background to that: Textview with green_bar background

When the whole gray bar needs to be converted to green.

Both are 9-patch png images. These are the originals:

gray_bargreen_bar

, , , , . ? , , , , . , 9--, , .

!

+5
1

, , , . , 9- .

, 9- , , . , , 9- . 9- . , , .

, .

0

All Articles