4
我試圖使用TransitionDrawable爲了在播放/暫停圖標之間切換。當我第一次點擊播放按鈕時,播放圖標會保留,暫停按鈕會出現在播放圖標的頂部。當我再次點擊暫停圖標消失,播放按鈕在那裏。TansitionDrawable第一個元素不會消失
代碼:的onClick運行此方法
private void startOrPause() {
TransitionDrawable drawable = (TransitionDrawable) mPlayBtn.getDrawable();
if (!isPlaying) {
drawable.startTransition(300);
} else {
drawable.reverseTransition(300);
}
isPlaying = !isPlaying;
}
XML:過渡
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_play"/>
<item android:drawable="@drawable/ic_pause"/>
</transition>
的ImageButton:
<ImageButton android:id="@+id/audio_layout_play_imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@drawable/play_pause_transition"
android:background="@android:color/transparent"
android:layout_marginLeft="4dp"
/>
我已經看了Ø在Android上的示例代碼和一些在互聯網上的指南和每個人都這樣做。
感謝您的幫助,
羅伊
讓你的圖片有白色背景,而不是透明的背景(我懷疑他們目前有),看看有沒有什麼幫助。 – CommonsWare
@CommonsWare非常感謝您的回答。它確實解決了我的問題,但我已經決定這是非常有限的背景色,所以我使用「mButton.animate()。alpha(0); mButtons.setImageResource(R.drawable ...); mButton.animate ).alpha(1).setStartDelay(300); – royB