Android(安卓)RotateAnimation动画不能旋转的问题
16lz
2021-01-26
今天要做一个Android RotateAnimation动画,但仿照一个demo做了下死活没有旋转效果,通过认真比对终于找出问题了,原来是imageview的id不能使img_arrow,换个id为img_catogery_arrow就可以了哦你onCreate中绑定点击事件
private LinearLayout mLinearLayout;private ImageView mImageUnfold;@Overrideprotected 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); } }
更多相关文章
- Android重写View并且自定义属性(二)
- Android(安卓)Studio 常用控件和常用布局的介绍
- Android调用第三方百度APP进行导航
- android 调用系统命令实现关机
- Recovery模式的命令行参数
- android在学习——Menu背景图片,背景色的设置
- Android(安卓)pcm文件播放方法(AudioTrack)
- android播放网络或者本地视频(截取某帧做封面)VideoView原生控件
- Android(安卓)编程下 Touch 事件的分发和消费机制(一)