今天要做一个Android RotateAnimation动画,但仿照一个demo做了下死活没有旋转效果,通过认真比对终于找出问题了,原来是imageview的id不能使img_arrow,换个id为img_catogery_arrow就可以了哦你onCreate中绑定点击事件
private LinearLayout mLinearLayout;
private ImageView mImageUnfold;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLinearLayout=(LinearLayout) findViewById(R.id.layout_cid);
mImageUnfold=(ImageView)findViewById(R.id.img_catogery_arrow);
mLinearLayout.setOnClickListener(new RotateButtonListener());
}
点击事件中实现动画效果
class RotateButtonListener implements OnClickListener{
public void onClick(View v) {
AnimationSet animationSet = new AnimationSet(true);
//参数1:从哪个旋转角度开始
//参数2:转到什么角度
//后4个参数用于设置围绕着旋转的圆的圆心在哪里
//参数3:确定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标
//参数4:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴
//参数5:确定y轴坐标的类型
//参数6:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setDuration(1000);
animationSet.addAnimation(rotateAnimation);
image.startAnimation(animationSet);
}
}