非常簡單的sample 關於animation
1. 先在res/anim 目碌下加上一個xml:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:interpolator= "@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset="700"
android:duration="2000"
android:repeatCount="10"
/>
</set>
2. 在res/drawable 加上圖片 (my_image.jpg)
3. 在main.xml 加上
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/spaceshipImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
</LinearLayout>
4. 在主要的.java 加編寫
package com.android.ani;
import com.android.ani.R;
import android.app.Activity;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class animDo extends Activity {
LinearLayout mLinearLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
spaceshipImage.startAnimation(hyperspaceJumpAnimation); !!!!!!!!!!!!!! 問題在這句 !!!!!!!!!!!!!
}
}
我用模擬器(emulator)運行此app (rum as andriod application) 時出現以下error message:
The application moandroid (process com.android.ani) has stopped unexpectedly. Please try again.
我已經跟足網站指示, 而且再與其他網站比對, 如果文字上有錯漏, 應該不能build project, 也不會出現此error message.
本人 android SDK 是: version2.2, API 8
我見sample code 裡面有一個default.properties, 內容是:
target=android-3
而我的是:
target=android-8
請問有沒有問題呢??