1
我一直在研究Android中的動畫學習,並且根據教程,目前相當簡單。不過,我想讓這些動畫比教程所教的內容更進一步。在Android動畫期間更改圖像
我想模擬一個模具的滾動。這是我的代碼將視圖添加到視圖。
<ImageButton android:id="@+id/dice" android:clickable="true"
android:onClick="rollDie" android:src="@drawable/dice_sides"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@null" />
來源dice_sides
是一個級別列表。
添加初始動畫很容易。在活動中的rollDie
方法,我這樣做:
/**
* Roll of the die.
*
* @param view
* The view that is being acted upon.
*/
public void rollDie(View view) {
// Setup the animation.
Animation move = AnimationUtils.loadAnimation(view.getContext(),
R.anim.move);
View dice = findViewById(R.id.dice);
dice.setAnimation(move);
move.start();
}
這工作正常。骰子圖像來回搖晃。
我想要發生的是在模型中顯示各種數字,直到它停在動畫的最後部分。不幸的是,我無法找到如何與第一個動畫一起做第二個動畫。有人提到使用處理程序,但我不太明白在這種情況下如何使用它們。如果有人能指引我正確的方向,我將不勝感激。
(根據記錄,這裏是dice_sides。)
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/die.1" />
<item android:maxLevel="1" android:drawable="@drawable/die.2" />
<item android:maxLevel="2" android:drawable="@drawable/die.3" />
<item android:maxLevel="3" android:drawable="@drawable/die.4" />
<item android:maxLevel="4" android:drawable="@drawable/die.5" />
<item android:maxLevel="5" android:drawable="@drawable/die.6" />
</level-list>