Android(安卓)点击View Rotate旋转带视图动画
16lz
2021-01-26
关闭状态
打开状态
切换有500秒动画
初始化恢复打开关闭状态时,动画durationMillis设置为0
private void rotateOpen(final View v,long durationMillis) { 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 animation = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(durationMillis);//设置动画持续时间/** 常用方法 */ //animation.setRepeatCount(0);//设置重复次数 //animation.setStartOffset(long startOffset);//执行前的等待时间 //animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态 animationSet.addAnimation(animation); animationSet.setFillAfter(true); animationSet.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // v.clearAnimation(); // v.setRotation(180f); } @Override public void onAnimationRepeat(Animation animation) { } }); // v.setAnimation(animation); // animation.startNow(); v.startAnimation(animationSet); }
private void rotateClose(final View v,long durationMillis) { // 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 animation = new RotateAnimation(180f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(durationMillis);//设置动画持续时间 //animation.setRepeatCount(0);//设置重复次数 //animation.setStartOffset(long startOffset);//执行前的等待时间 //animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态 animationSet.addAnimation(animation); animationSet.setFillAfter(true); // v.setAnimation(animation); // animation.startNow(); v.startAnimation(animationSet); }
视图动画只改变样子不改变原有属性,所以比较长。。。
简单快速实现见:
Android 点击View Rotate旋转带视图动画
http://blog.csdn.net/RichieZhu/article/details/52201679
更多相关文章
- android 多通知 参数问题, PendingIntent:有用的requestCode参数
- Android(安卓)UI 之 RecyclerView实现常见首页布局
- android 中关于SimpleAdapter构造参数的问题
- Android:为什么声明控件和控件赋值要分开?
- Android(安卓)程式开发:(十)基本控件 —— 10.2 Button,ImageButton
- Android控件之AutoCompleteTextView(自动匹配输入的内容)
- Android应用之PopupWindow显示位置详解
- Android(安卓)Toolbar控件
- Android控件复习之TextView与EditText