我需要重複void x次。我如何做到這一點?謝謝! P.S.例如,x = 3,我需要開始動畫3次。 P.S.2。對不起,我的英文不好如何重複某些方法
public void animation (View v){
view = new ImageView(getApplicationContext());
view.setImageResource(R.drawable.lemon_prig);
view.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
fl = (FrameLayout)findViewById(R.id.frameLayout1);
fl.addView(view);
Random random = new Random();
TranslateAnimation anim = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, random.nextFloat(),
Animation.RELATIVE_TO_PARENT, random.nextFloat(),
Animation.RELATIVE_TO_PARENT, -0.05f,
Animation.RELATIVE_TO_PARENT, 1.5f);
anim.setDuration(1800);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation paramAnimation) { }
public void onAnimationRepeat(Animation paramAnimation) { }
public void onAnimationEnd(Animation paramAnimation) {
fl.post(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
fl.removeAllViews();
}
});
}
});
}
});
view.startAnimation(anim);
}
public void limonplus(View v){
count=count + i;
animation(v);
}
先學編程! –