android 补间动画重复次数,9.1.5 setRepeatCount方法:设置重复次数
9.1.5? setRepeatCount方法:設(shè)置重復(fù)次數(shù)
【功能說明】該方法用于設(shè)置一個動畫效果重復(fù)執(zhí)行的次數(shù)。Android系統(tǒng)默認(rèn)每個動畫僅執(zhí)行一次,通過該方法可以設(shè)置動畫執(zhí)行多次。
【基本語法】public void setRepeatCount (int repeatCount)
其中,參數(shù)repeatCount為重復(fù)執(zhí)行的次數(shù)。如果設(shè)置為n,則動畫將執(zhí)行n+1次。
【實(shí)例演示】下面通過代碼來演示如何連續(xù)執(zhí)行多次動畫效果。public?class?firstActivity?extends?Activity?{
/**?Called?when?the?activity?is?first?created.?*/
@Override
public?void?onCreate(Bundle?savedInstanceState)?{???????????????//重載onCreate方法
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final?ImageViewimage=(ImageView)findViewById(R.id.imageView1);?//ImageView對象
Buttonbtn1=(Button)findViewById(R.id.button1);?????????????//按鈕對象
Buttonbtn2=(Button)findViewById(R.id.button2);
final?AnimationtranslateAnimation=newTranslateAnimation(0,200,0,200);?????????????????????????????????????????????????????????????????//移動動畫效果
btn1.setOnClickListener(new?View.OnClickListener()?{????????????//設(shè)置監(jiān)聽器
@Override
public?void?onClick(View?v)?{
//?TODO?Auto-generated?method?stub
translateAnimation.setDuration(3000);???????????????//設(shè)置動畫持續(xù)時間
translateAnimation.setRepeatCount(2);???????????????//設(shè)置重復(fù)次數(shù)
image.setAnimation(translateAnimation);?????????????//設(shè)置動畫效果
translateAnimation.startNow();??????????????????????//啟動動畫
}
});
btn2.setOnClickListener(new?View.OnClickListener()?{????????????//設(shè)置監(jiān)聽器
@Override
public?void?onClick(View?v)?{
//?TODO?Auto-generated?method?stub
translateAnimation.cancel();????????????????????????//取消動畫執(zhí)行
}
});
}
}
在這段代碼中,首先初始化了一個移動的動畫效果translateAnimation。然后,在***個按鈕監(jiān)聽器中,通過setDuration方法設(shè)置動畫持續(xù)時間,通過setRepeatCount方法設(shè)置重復(fù)次數(shù),并為image對象設(shè)置動畫效果,***使用startNow方法啟動動畫效果。在第二個按鈕監(jiān)聽器中,調(diào)用cancel方法取消動畫執(zhí)行。讀者執(zhí)行這段代碼,當(dāng)點(diǎn)擊"執(zhí)行動畫"按鈕時,將看到動畫被重復(fù)執(zhí)行了兩次,也就是總共執(zhí)行了3次動畫。
注意:這里設(shè)置的是動畫重復(fù)執(zhí)行的次數(shù),而不是動畫執(zhí)行的次數(shù)。故動畫執(zhí)行的次數(shù)為動畫重復(fù)執(zhí)行的次數(shù)加1。
【責(zé)任編輯:book TEL:(010)68476606】
點(diǎn)贊 0
總結(jié)
以上是生活随笔為你收集整理的android 补间动画重复次数,9.1.5 setRepeatCount方法:设置重复次数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux中 pwd *****,lin
- 下一篇: Android多个imei如何获取,如何