我試圖使用Android的動畫框架讓我的ImageView以菱形圖案移動。這裏是我的animation.xml:Android動畫XML問題
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
<translate
android:fromXDelta="40%p" android:toXDelta="90%p"
android:fromYDelta="10%p" android:toYDelta="40%p"
android:duration="500" android:startOffset="0"/>
<translate
android:fromXDelta="90%p" android:toXDelta="40%p"
android:fromYDelta="40%p" android:toYDelta="90%p"
android:duration="500" android:startOffset="500"/>
<translate
android:fromXDelta="40%p" android:toXDelta="10%p"
android:fromYDelta="90%p" android:toYDelta="40%p"
android:duration="500" android:startOffset="1000"/>
<translate
android:fromXDelta="10%p" android:toXDelta="40%p"
android:fromYDelta="40%p" android:toYDelta="10%p"
android:duration="500" android:startOffset="1500"/>
</set>
我的佈局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
</FrameLayout>
而且我在onStart:
protected void onStart() {
super.onStart();
ImageView img = (ImageView)findViewById(R.id.img);
Animation a = AnimationUtils.loadAnimation(this, R.anim.diamond);
img.startAnimation(a);
}
當我開始了我的申請,我看是2秒的黑屏,然後我的圖像彈出到屏幕的左上角。如果我刪除除了其中一個翻譯動畫之外的所有內容,我將看到圖像以對角線移動。
我寧願使用XML來定義動畫而不是Java。
有沒有人有任何見解我如何看到整個動畫?
-Dan
它似乎與使用「%p」有關。如果我將「%p」更改爲「%」,則整個動畫都可以工作,但現在只限於屏幕的一小部分。根據文檔「%」與對象有關係,「%p」與對象的父對象相關,這正是我想要的。這就解釋了爲什麼它只是將動畫製作成小方塊。 – Dan 2011-02-11 19:00:41
爲了進一步闡明,我想使用XML來定義我的動畫相對於我的動畫的ImageView的父級。我不會接受任何說框架被破壞的答案,我也不會接受一個答案,要求動畫在Java中定義。 – Dan 2011-02-15 13:32:06