public class MainActivity extends Activity {
ImageView imv, imv2;
int dra[] = { R.drawable.bubble0, R.drawable.bubble1, R.drawable.bubble2,
R.drawable.bubble3, };
int i, j;
Animation am;
int tiger[] = { R.drawable.wc0000, R.drawable.wc0001, R.drawable.wc0002,
R.drawable.wc0003, R.drawable.wc0004, R.drawable.wc0005,
R.drawable.wc0006, R.drawable.wc0007, };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imv = (ImageView) this.findViewById(R.id.imageView1);
imv2 = (ImageView) this.findViewById(R.id.imageView2);
//氣泡動畫
imv.postDelayed(new Runnable() {
@Override
public void run() {
imv.setImageResource(dra[i % dra.length]);
i++;
imv.postDelayed(this, 500);
}
}, 500);
//老虎圖片監聽
imv2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "散步..", Toast.LENGTH_SHORT)
.show();
am = new TranslateAnimation(30, 320, 0, 0);
//設定移動路徑(x1,x2,y1,y2);
am.setDuration(10000);
// 動畫開始到結束的時間(毫秒)
am.setRepeatCount(-1);
//0代表只跑一次,-1代表一直重複
am.startNow();
//動畫開始
imv2.setAnimation(am);
imv2.postDelayed(new Runnable() {
@Override
public void run() {
imv2.setImageResource(tiger[j % tiger.length]);
j++;
imv2.postDelayed(this, 100);
}
}, 100);
}
});
}
}
留言列表