step by step.
目录
1.layout改变实现动态(4次移动位置循环组成):
核心代码:
整个代码:
public void keeprun(imageview cat){
int t = 0;
for(int i=0;i<50;i++){
run(cat,t);
t+=800;
}
}
public void run(imageview cat,int t){
handler handler = new handler();
handler.postdelayed(new runnable() {
@override
public void run() {
relativelayout.layoutparams temp = (relativelayout.layoutparams) cat.getlayoutparams();
temp.setmargins(0,270,0,0);
cat.setrotation(10);
cat.setlayoutparams(temp);
}
}, t);
handler.postdelayed(new runnable() {
@override
public void run() {
relativelayout.layoutparams temp = (relativelayout.layoutparams) cat.getlayoutparams();
temp.setmargins(0,270,0,0);
cat.setlayoutparams(temp);
cat.setrotation(0);
}
}, t+=200);//0.1秒后执行runnable中的run方法
handler.postdelayed(new runnable() {
@override
public void run() {
relativelayout.layoutparams temp = (relativelayout.layoutparams) cat.getlayoutparams();
temp.setmargins(0,200,0,0);
cat.setrotation(-10);
cat.setlayoutparams(temp);
}
}, t+=200);//0.1秒后执行runnable中的run方法
handler.postdelayed(new runnable() {
@override
public void run() {
relativelayout.layoutparams temp = (relativelayout.layoutparams) cat.getlayoutparams();
temp.setmargins(0,200,0,0);
cat.setlayoutparams(temp);
cat.setrotation(0);
}
}, t+=200);//0.1秒后执行runnable中的run方法
}
发表评论