RotateAnimation类:旋转变化动画类
来源:互联网 发布:python中的sleep函数 编辑:程序博客网 时间:2024/05/22 05:23
RotateAnimation旋转坐标系为以旋转点为坐标系(0,0)点。x轴为0度,顺时针方向旋转一定的角度。
1.RotateAnimation(fromDegrees, toDegrees) [默认以View左上角顶点为旋转点]。
X轴顺时针转动到fromDegrees为旋转的起始点,
X轴顺时针转动到toDegrees为旋转的起始点。
如fromDegrees=0,toDegrees=90;为左上角顶点为旋转点。0度为起始点,90度为终点。进行旋转,旋转了90度
如fromDegrees=60,toDegrees=90;为左上角顶点为旋转点。60度为起始点,90度为终点。进行旋转,旋转了90-60=30度
2.RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
(pivotX,pivotY)为旋转点。pivotX为距离左侧的偏移量,pivotY为距离顶部的偏移量。即为相对于View左上角(0,0)的坐标点。
如View width=100px,height=100px
RotateAnimation(0,10,100,100);则以右下角顶点为旋转点,从原始位置顺时针旋转10度
RotateAnimation(0,90,50,50);则以View的中心点为旋转点,旋转90度
3.RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)
pivotXType, pivotXValue, pivotYType, pivotYValue 旋转点类型及其值。
Animation.ABSOLUTE为绝对值 其他为百分比。这个和平移动画的一样,不了解可以去那看
如RotateAnimation(0, 90, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 按中心点旋转90度
效果和2例中的RotateAnimation(0,90,50,50);则以View的中心点为旋转点,旋转90度 。效果一样
new RotateAnimation(0, 180, centerX,centerY);
第一个参数表示动画的起始角度,第二个参数表示动画的结束角度,第三个表示动画的旋转中心x轴,第四个表示动画旋转中心y轴。
rotateAnimation.setDuration(1000 * 20);
表动画持续20s。
rotateAnimation.setFillAfter(true);
ture表示动画结束后停留在动画的最后位置,false表示动画结束后回到初始位置,默认为false。
mView.startAnimation(rotateAnimation);
表示在mView中启动动画。
RotateAnimation类是Android系统中的旋转变化动画类,用于控制View对象的旋转动作,该类继承于Animation类。RotateAnimation类中的很多方法都与Animation类一致,该类中最常用的方法便是RotateAnimation构造方法。
【基本语法】public RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明
fromDegrees:旋转的开始角度。
toDegrees:旋转的结束角度。
pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
pivotXValue:X坐标的伸缩值。
pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
pivotYValue:Y坐标的伸缩值。
【实例演示】下面通过代码来演示如何设置一个简单的旋转变化动画效果。
- public class firstActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) { //重载onCreate方法
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象
- Button btn1=(Button)findViewById(R.id.button1); //按钮对象
- Button btn2=(Button)findViewById(R.id.button2);
- final Animation rotateAnimation = new
- RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
- //设置旋转变化动画对象
- btn1.setOnClickListener(new View.OnClickListener() { //设置监听器
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- rotateAnimation.setDuration(3000); //持续时间
- image.setAnimation(rotateAnimation); //设置动画
- imagev.startAnimation(rotateAnimation);//启动动画
- }
- });
- btn2.setOnClickListener(new View.OnClickListener() { //设置监听器
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- rotateAnimation.cancel(); //取消动画执行
- }
- });
- }
- }
在这段代码中,首先通过RotateAnimation构造方法创建了一个旋转变化的动画对象。然后,在第一个按钮监听器中设置了动画的持续时间,之后启动该动画。在第二个按钮监听器中取消该动画
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类
- RotateAnimation类:旋转变化动画类的使用和总结
- RotateAnimation类:旋转变化动画类,自定义控件通过rotateAnimation实现特效
- Android利用RotateAnimation实现旋转变化动画
- RotateAnimation旋转动画Demo
- 旋转动画 RotateAnimation
- 旋转动画RotateAnimation
- Android 中的动画 RotateAnimation类
- Android RotateAnimation动画不能旋转的问题
- 旋转动画——RotateAnimation的讲解
- android RotateAnimation设置中心点旋转动画
- iOS中delegate(委托)的使用
- cocos2dx之加速器
- 迭代MapReduce的核心资料索引
- iframe 内存释放
- Django学习系列(二)--第一个App
- RotateAnimation类:旋转变化动画类
- C++调用exe可执行文件
- Oracle和SQLServer 数据类型映射
- JDK,Eclipse,Selenium , Maven下载
- 30款精心挑选的JavaScript库和工具(一)
- C++中的动态内存与智能指针
- php http模拟POST提交上传图片
- 转载 最新版ccs-lua库api
- 制氧机的分子筛原来是歼十军用技术