我正在嘗試一個簡單的幀框架動畫。我的動畫按鈕點擊工作,但我希望它應該在活動啓動或加載時啓動。我已經嘗試onWindowFocusChanged()方法也可以按照文檔中的說明啓動動畫。我認爲我犯了一個愚蠢的錯誤。任何人都有想法。我的動畫沒有開始?
public class FirstActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button btnalarm;
AnimationDrawable AniFrame;
ImageView images;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
images=(ImageView)findViewById(R.id.myImageView);
images.setBackgroundResource(R.drawable.demo_animation);
AniFrame = (AnimationDrawable)images.getBackground();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.v("in focus", "in focus");
AniFrame.start();
}
demo_animation.xml文件---->
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/a" android:duration="50" />
<item android:drawable="@drawable/b" android:duration="50" />
<item android:drawable="@drawable/c" android:duration="50" />
<item android:drawable="@drawable/d" android:duration="50" />
<item android:drawable="@drawable/e" android:duration="50" />
<item android:drawable="@drawable/f" android:duration="50" />
<item android:drawable="@drawable/h" android:duration="50" />
<item android:drawable="@drawable/i" android:duration="50" />
<item android:drawable="@drawable/j" android:duration="50" />
<item android:drawable="@drawable/k" android:duration="50" />
</animation-list>
感謝您的答覆。我嘗試了上面的線程邏輯,仍然沒有開始動畫。 –
你可以請把包含框架動畫的xml文件。 –
是的,我把xml文件,請檢查編輯的問題。 –