安卓过渡可绘制多个项目
我想在Android中创建一个带有文本和背景图像的按钮。背景图像应每 X 次交叉淡入淡出。
我使用带有2张图像的TransitionDrawable进行这项工作。
但是我无法让它与超过2张图像一起使用。
我有什么 :
在Java代码中,我创建了一个按钮并设置了一个背景(这是在XML中定义的TransitionDrawable)。然后我开始过渡。
final Button b = new Button(getApplicationContext());
b.setTextColor(getResources().getColor(R.color.white));
b.setText("Some text");
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.tile));
StateListDrawable background = (StateListDrawable) b.getBackground();
TransitionDrawable td = (TransitionDrawable) background.getCurrent();
td.startTransition(2000);
在XML中,我在磁贴中定义.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#449def" />
</shape>
</item>
<item android:drawable="@drawable/transition">
<shape>
<solid
android:color="#0000ff" />
</shape>
</item>
</selector>
最后是过渡.xml
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/desert"/>
<item android:drawable="@drawable/hydrangeas" />
<item android:drawable="@drawable/jellyfish" />
</transition>
现在的效果是,当我启动应用程序时,将显示沙漠图像。此图像会像它应该的那样交叉淡入绣球花图像。但是水母的图像从未显示过。
在TransitionDrawables的文档中,它指出您可以指定2个以上的可绘制对象,但我无法使其正常工作。
我也在没有任何XML的情况下尝试了这个,但在纯JAVA中,但这给出了完全相同的问题:-(