I want to perform sliding animation of On OFF button of toggle button.How I can do that.How to use animation in order to make slide between ON/OFF OFF/ON
Asked
Active
Viewed 3,354 times
1
-
See if [this](http://stackoverflow.com/questions/19008555/how-can-i-create-animated-togglebutton) helps. – MysticMagicϡ Sep 30 '14 at 08:57
1 Answers
0
You will need an animation-list:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" >
<item android:drawable="@drawable/a14" android:duration="200" />
<item android:drawable="@drawable/a15" android:duration="200" />
<item android:drawable="@drawable/a16" android:duration="200" />
<item android:drawable="@drawable/a17" android:duration="200" />
<item android:drawable="@drawable/a18" android:duration="200" />
<item android:drawable="@drawable/a19" android:duration="200" />
<item android:drawable="@drawable/a20" android:duration="200" />
</animation-list>
where each of a14
to a20
is an image. Then you will need to create a selector drawable which defines how a button will look when it is in "on" state and how it will look when it is in "off" state. The drawable will point to the animation-list
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/animatedbutton_on" />
<item android:state_checked="false" android:drawable="@drawable/animatedbutton_off" />
</selector>
The selector then becomes the background of your toggle button.
Source: animated toggle button

Community
- 1
- 1

An SO User
- 24,612
- 35
- 133
- 221
-
1Please explain that how I will be able to use animation-list xml in my Activity....How I am going to use variables of Animation...Please write the complete code. – vikram singh chandel Sep 30 '14 at 10:24