我有一個(gè)來自 png 和 android:oneshot="true" 的可繪制動(dòng)畫,因?yàn)槲也幌M麆?dòng)畫不斷播放,但只有在我激活它時(shí)才播放。問題是它只播放一次,當(dāng)我嘗試時(shí)myAnimation.play();它不會(huì)再次播放。我試過myAnimation.stop();并再次播放,但它使動(dòng)畫在動(dòng)畫結(jié)束前停止。當(dāng)我用 開始動(dòng)畫時(shí),也會(huì)發(fā)生同樣的事情myAnimation.run();,盡管我不知道其中的區(qū)別。//in onCreate() methodimageView = findViewById(R.id.imageView);imageView.setBackgroundResource(R.drawable.animation_drawable);myAnimation = (AnimationDrawable) imageView.getBackground();//Triggers in somewhere else in a threadmyAnimation.start();//animation_drawable.xml<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/animation_drawable" android:oneshot="true"> <item android:drawable="@drawable/kapali" android:duration="0"/> <item android:drawable="@drawable/acik" android:duration="500"/> <item android:drawable="@drawable/kapali" android:duration="0"/></animation-list>
1 回答

絕地?zé)o雙
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
在animation_drawable.xml
您擁有的中android:oneshot="true"
,刪除它或?qū)⑵涓臑?code>false.
嘗試使用
myAnimation.setOneShot(false);
在 start() 方法之前。
當(dāng)你想停止動(dòng)畫使用
myAnimation.stop();
對(duì)于您的情況,在停止動(dòng)畫(或設(shè)置 oneshot=true)后,要重新啟動(dòng)動(dòng)畫,請(qǐng)使用
myAnimation.setVisible(/*visible=*/true,/*restart=*/true);
添加回答
舉報(bào)
0/150
提交
取消