device-2013-06-07-092107    device-2013-06-07-092120  


 

 

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);

}
});

}

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 小Chiu 的頭像
    小Chiu

    Cuiu's Home

    小Chiu 發表在 痞客邦 留言(0) 人氣()