Android RotateAnimation动画不能旋转的问题

今天要做一个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);
       }
    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值