2

I am trying to animate alternating background colours for a TextView, by changing the background drawables with the TransitionDrawable class. This is the result I am getting:

enter image description here

The problem is that the second drawable is smaller than the first one , and as a result the green background is always visible around the sides. I need the blue background to completely cover the green one. I just cannot figure out why this is the case.

some layout file:

<TextView
        android:id="@+id/alertCrumb"
        style="@style/Custom.TextAppearance.AppCompat.Caption"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/crumb_animated"
        android:textColor="@android:color/white"/>

crumb_animated.xml

<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

            <solid android:color="@android:color/holo_green_light" >
            </solid>

            <padding
                android:bottom="1dp"
                android:left="4dp"
                android:right="4dp"
                android:top="1dp" >
            </padding>

            <corners android:radius="2dp" >
            </corners>

        </shape>
    </item>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

            <solid android:color="@android:color/holo_blue_dark" >
            </solid>

            <padding
                android:bottom="1dp"
                android:left="4dp"
                android:right="4dp"
                android:top="1dp" >
            </padding>

            <corners android:radius="2dp" >
            </corners>

        </shape>
    </item>
</transition>

calling it in java:

final TransitionDrawable background = (TransitionDrawable) alertCrumb.getBackground();
        background.startTransition(500);
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                background.reverseTransition(1000);
                handler.postDelayed(this, 1000);
            }
        }, 2000);
Crocodile
  • 4,972
  • 7
  • 35
  • 60

0 Answers0