AndroidUI 视图动画-旋转动画效果 (RotateAnimation)
来源:互联网 发布:矩阵的谱范数怎么求 编辑:程序博客网 时间:2024/06/05 20:17
RotateAnimation,能实现Android的视图的旋转效果,废话不多说直接上代码。
新建一个Android 项目,在activity_main.xml中添加一个按钮,然后使用RelativeLayout布局,使按钮居中:
<Button android:id="@+id/btnRotateAnim" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="178dp" android:text="@string/btnRotateAnimText" />
在MainActivity.java中添加以下代码:
private RotateAnimation rotate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rotate=new RotateAnimation(0, 360); rotate.setDuration(3000); findViewById(R.id.btnRotateAnim).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {v.startAnimation(rotate);}}); }
然后行程序,即可看到,按钮根据某一个点来进行旋转:
同样也可以使用按钮根部某个特定的点进行旋转,只需要将创建的RotateAnimation更改为以下:
//rotate=new RotateAnimation(0, 360); rotate=new RotateAnimation(0, 360, 200, 100);
如下效果 :
那么,如果想让按钮根据他自身的某个点进行旋转,比如根据自身的中心点旋转,其实也很简单,只需要将RotateAnimation代码更改为如下:
//rotate=new RotateAnimation(0, 360); //rotate=new RotateAnimation(0, 360, 200, 100); rotate=new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
如何通过XML配置RotateAnimation的动画效果呢?
新建一个Android Xml文件:
在文件中添加如下代码:
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:duration="3000" android:pivotX="50%" android:pivotY="50%"> </rotate>在XML中pivotX 和pivotY是支持百分比的,如果只填数字的话,系统会默认当做像素来识别:
程序中代码是:
v.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.rotate1));
只需要这样就可以同样实现旋转效果了。
0 0
- AndroidUI 视图动画-旋转动画效果 (RotateAnimation)
- AndroidUI 视图动画-透明动画效果 (AlphaAnimation)
- AndroidUI 视图动画-移动动画效果 (TranslateAnimation)
- AndroidUI 视图动画-缩放动画效果 (ScaleAnimation)
- AndroidUI 视图动画-自定义动画效果 (Animation)
- rotateAnimation 动画效果(转载)
- AndroidUI 视图动画-混合动画效果 (AnimationSet)/动画效果监听
- RotateAnimation旋转动画Demo
- 旋转动画 RotateAnimation
- 旋转动画RotateAnimation
- Android 动画之RotateAnimation应用详解(旋转动画效果 )(转载)
- ios旋转视图 视图动画效果CGAffineTransformRotate
- 【Android动画九章】-RotateAnimation(旋转动画)和ScaleAnimation(尺寸动画)
- RotateAnimation类:旋转变化动画类
- Android利用RotateAnimation实现旋转变化动画
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- 安装SparkR
- USACO 2.2.3 Runaround Numbers
- Best Cow Line
- 【面试笔试】二叉树相关操作
- 个人对Fragment的一些理解
- AndroidUI 视图动画-旋转动画效果 (RotateAnimation)
- 学习笔记 - java创建文件夹
- 如何在ROM中集成可卸载的APK
- Scipy教程 - 距离计算库scipy.spatial.distance
- fpga设计思想(三):毛刺、fmax、tsu、tH、 tco
- 07lambda、filter、map应用
- 【笔试面试】字符串相关操作
- ssh之openssh使用
- <AE之路>视频制式基础