Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

android - Animate selector/state transitions

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.

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.

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.

Thanks in advance.

EDIT:

I guess I have found something useful there's a activated_background.xml in Androidandroid-sdkplatformsandroid-API_VERSIONdata esdrawable 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>

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.

question from:https://stackoverflow.com/questions/9221535/animate-selector-state-transitions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Added in api 21 "StateListAnimator"

http://developer.android.com/reference/android/animation/StateListAnimator.html

I know this is an old question but this may help future people looking to do this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...