动画选择/状态转换 [英] Animate selector/state transitions
问题描述
我有一个简单的选择为我的ListView
I have a simple selector for my ListView
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/yellow_arc" android:state_activated="true"/>
<item android:drawable="@drawable/yellow_nonarc" android:state_activated="false"/>
</selector>
我想这些动画可绘制之间的过渡时的意见状态,从激活不激活,改变正相反。
I want to animate the transition between these drawables when the state of the views are changed from activated to not-activated and vica versa.
如果您运行的example在API的演示,而视图的激活状态改变时,你会看到一个明显的淡入/淡出动画。
If you run the example in API demos you will see an obvious fade-in/fade-out animation while the activated state of the view is changed.
所以,我要的是一个自定义动画,而视图的状态被改变。我觉得应该通过XML来实现,但我无法找到一个方法。
So what I want is a custom animation while the state of the view is changed. I think it should be done via xml but I couldn't find a way.
先谢谢了。
编辑:
我想我已经找到有用的东西有一个 activated_background.xml
在 \\ Android的\\ Android的SDK \\ \\平台Android的API_VERSION \\ DATA \\水库\\绘制
包括
I guess I have found something useful there's a activated_background.xml
in \Android\android-sdk\platforms\android-API_VERSION\data\res\drawable
which includes
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_activated="true" android:drawable="@android:drawable/list_selector_background_selected" />
<item android:drawable="@color/transparent" />
</selector>
因此,在API-演示通过声明 exitFadeDuration
achieveing这种淡出动画的例子。然而,这不是我想要 ..我想声明的自定义动画以来的淡入/淡出动画状态可绘制之间的过渡不会什么好看的我可绘。
So the example in API-demos achieveing this fade-out animation by declaring an exitFadeDuration
. However, this is not exactly what I want.. I want to declare custom animations for the transition between the state drawables since the fade-in/fade-out animation does not look good for my drawables.
推荐答案
我猜的 TransitionDrawable 可以帮助你做到这一点。
I guess TransitionDrawable could help you to accomplish this.
您可以在这里检查了答案:
<一href=\"http://stackoverflow.com/questions/2614545/animate-change-of-view-background-color-in-android#answer-3208800\">Animate在Android设备上查看背景颜色的变化
You can check the answer here: Animate change of view background color in Android
这篇关于动画选择/状态转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!