簡體   English   中英

如何在Android中執行ON OFF Toggle按鈕的滑動動畫

[英]how to perform sliding animation of ON OFF Toggle button in android

我想執行切換按鈕的ON OFF按鈕的滑動動畫。我該怎么做。如何使用動畫在ON / OFF OFF / ON之間進行滑動

您將需要一個動畫列表:

<?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>    

其中a14a20均為圖像。 然后,您將需要創建一個選擇器drawable,它定義按鈕在“打開”狀態時的外觀以及在“關閉”狀態時的外觀。 drawable將指向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>    

然后,選擇器將成為切換按鈕的背景。

來源: 動畫切換按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM