我有picView.startAnimation(anim);
和picView.startAnimation(anim2);
,但只有picView.startAnimation(anim2);
有效。
当我删除第二个动画时,只有picView.startAnimation(anim);
有效。
我希望两个动画同时运行,我做错了什么?
我的代码
public class PicView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pic_view);
LinearLayout myLL = (LinearLayout) findViewById(R.id.LinearLayout2);
final ImageView picView = new ImageView(this);
myLL.addView(picView);
final TextView tv = new TextView(this);
myLL.addView(tv);
Animation anim = AnimationUtils.loadAnimation(PicView.this, R.anim.anim_button);
Animation anim2 = AnimationUtils.loadAnimation(PicView.this, R.anim.anim_button2);
picView.setImageResource(R.drawable.a0000);
picView.startAnimation(anim);
picView.startAnimation(anim2);
}
}
答案 0 :(得分:0)
您必须创建AnimationSet
。
这样的事情:
Animation anim = AnimationUtils.loadAnimation(PicView.this, R.anim.anim_button);
Animation anim2 = AnimationUtils.loadAnimation(PicView.this, R.anim.anim_button2);
AnimationSet as = new AnimationSet(true);
as.addAnimation(anim);
as.addAnimation(anim2);
viewYouWantToAnimate.setAnimation(as);
as.start();