Skip to content

Layer List Color Animation

Weiping Huang edited this page Apr 6, 2017 · 2 revisions

WoWoLayerListColorAnimation is almost the same as WoWoStateListColorAnimation, but it's used to change the color of LayerDrawable. The LayerDrawable should be the form in .xml file:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/item1"
        android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
        <shape android:shape="oval">
            <size android:width="200dp" android:height="200dp"/>
            <solid android:color="@color/black"/>
        </shape>
    </item>

    ...

    <item android:id="@+id/item5"
        android:top="100dp" android:left="100dp" android:bottom="20dp" android:right="20dp">
        <shape android:shape="rectangle">
            <size android:width="80dp" android:height="80dp"/>
            <corners android:bottomRightRadius="80dp"/>
            <solid android:color="@color/red"/>
        </shape>
    </item>
</layer-list>

In the activity file:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addAnimations(findViewById(R.id.test1), Chameleon.RGB);
    addAnimations(findViewById(R.id.test2), Chameleon.HSV);
}

private void addAnimations(View view, Chameleon chameleon) {
    ViewAnimation animation = new ViewAnimation(view);
    animation.add(WoWoLayerListColorAnimation.builder().page(0)
            .from("#000000", "#ff0000", "#00ff00", "#00ff00", "#ff0000")
            .to("#0000ff", "#00ff00", "#ff0000", "#ff0000", "#00ff00").chameleon(chameleon).build());
    animation.add(WoWoLayerListColorAnimation.builder().page(1)
            .from("#0000ff", "#00ff00", "#ff0000", "#ff0000", "#00ff00")
            .to("#000000", "#ff0000", "#00ff00", "#00ff00", "#ff0000").chameleon(chameleon).build());
    animation.add(WoWoLayerListColorAnimation.builder().page(2)
            .from("#000000", "#ff0000", "#00ff00", "#00ff00", "#ff0000")
            .to("#0000ff", "#00ff00", "#ff0000", "#ff0000", "#00ff00").chameleon(chameleon).build());
    animation.add(WoWoLayerListColorAnimation.builder().page(3).start(0).end(0.5)
            .from("#0000ff", "#00ff00", "#ff0000", "#ff0000", "#00ff00")
            .to("#ffff00", "#0000ff", "#000000", "#ff00ff", "#0000ff").chameleon(chameleon).build());
    animation.add(WoWoLayerListColorAnimation.builder().page(3).start(0.5).end(1)
            .from("#ffff00", "#0000ff", "#000000", "#ff00ff", "#0000ff")
            .to("#ff00ff", "#000000", "#0000ff", "#ffff00", "#000000").chameleon(chameleon).build());
    wowo.addAnimation(animation);
    wowo.setEase(ease);
    wowo.setUseSameEaseBack(useSameEaseTypeBack);
    wowo.ready();
}

As mentioned in TextView TextColor Animation, every animation that extends from SingleColorPageAnimation and MultiColorPageAnimation has a parameter named Chameleon which performs the discoloration job. Check Chameleon Wiki to know about the difference between RGB and HSV discoloration-styles and how they works.

WoWoLayerListColorAnimation extends MultiColorPageAnimation and PageAnimation. Check more implementation details in its superclasses.

Methods List of WoWoLayerListColorAnimation.builder()

Clone this wiki locally