3

I have an outer clip drawable (clip_drawable.xml) which embeds another transition drawable (transition_drawable.xml), which itself refers to 2 shape drawables.

clip_drawable.xml:

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="vertical"
    android:drawable="@drawable/transition_drawable"
    android:gravity="top" >

</clip>  

transition_drawable.xml:

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

    <item>
        <shape android:shape="oval" >
            <stroke
                android:width="3dp"
                android:color="@color/titan" />

            <gradient
                android:angle="270"
                android:centerColor="@android:color/transparent"
                android:centerY="0.4"
                android:startColor="@color/titan" />

            <padding
                android:bottom="10dp"
                android:left="15dp"
                android:right="15dp"
                android:top="10dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval" >
            <stroke
                android:width="3dp"
                android:color="@color/titan" />

            <gradient
                android:angle="270"
                android:centerColor="@android:color/transparent"
                android:centerY="0.1"
                android:startColor="@color/titan" />

            <padding
                android:bottom="10dp"
                android:left="15dp"
                android:right="15dp"
                android:top="10dp" />
        </shape>
    </item>

</transition>  

I want to use this compound drawable as a button background:

<Button
    android:id="@+id/continue_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/clip_drawable"
    android:text="@string/label_continue"
    android:textColor="@android:color/white"
    android:textSize="20sp" />

In the code I can refer to the ClipDrawable and set a level by saying:

final ClipDrawable clipDrawable = (ClipDrawable) button.getBackground();
clipDrawable.setLevel(3000);

But how can I get a reference to the transition drawable, in order to start the transition? It is not the solution to just write, this won't work of course:

final TransitionDrawable transitionDrawable = (TransitionDrawable) this.getResources()
                .getDrawable(R.drawable.transition_drawable);
transitionDrawable .startTransition(1000);
Andy
  • 488
  • 4
  • 13
  • you can't, ClipDrawable doesn't expose any API for getting child Drawables – pskink Mar 29 '15 at 16:53
  • very very inflexible this API :-(. The same is true, if my parent drawable is the transition drawable and the child drawable is the clip drawable. In this case I have no chance to set the level. – Andy Mar 29 '15 at 17:01
  • 1
    oh you can always call setLevel on the parent, it propagates down to children – pskink Mar 29 '15 at 17:04
  • thx for this hint, so my workaround would be that TransitionDrawable is the parent and ClipDrawable the child. Hope this works ... – Andy Mar 29 '15 at 17:07

0 Answers0