码迷,mamicode.com
首页 > 移动开发 > 详细

android运用旋转动画

时间:2015-10-08 18:31:54      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:android

Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果;第二类是 Frame 动画,即顺序播放事先做好的图像。本文分析 Tween动画的rotate实现旋转效果。下面直接给出代码,并且附近中有完整的demo


主类:

public class MainActivity extends ActionBarActivity {
    private ImageView infoOperatingIV;

    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        infoOperatingIV = (ImageView)findViewById(R.id.infoOperating);  //图片对象实例化
        Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);  //创建动画对象并实例化,tip为动画的文件
        LinearInterpolator lin = new LinearInterpolator();  
        
        operatingAnim.setInterpolator(lin);

        if (operatingAnim != null) {  
            infoOperatingIV.startAnimation(operatingAnim);  
        }  

    }


布局 activity_main.xml



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    tools:context="com.example.testanimation.MainActivity" >
 
<ImageView  
        android:id="@+id/infobg"  
        android:layout_width="200dp"  
        android:layout_height="200dp"  
        android:src="@drawable/cemung_out_roate"  
       />  
     <ImageView  
        android:id="@+id/infoOperating"  
        android:layout_width="200dp"  
        android:layout_height="200dp"  
        android:src="@drawable/cemung_in_roate"  
        />  
        

</RelativeLayout>

动画 tip.xml

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
    <rotate  
        android:fromDegrees="0"  
        android:toDegrees="359"
       
        android:duration="1300"  
        android:repeatCount="-1"  
        android:pivotX="50%"  
        android:pivotY="50%" />  
</set>

实例中的图片放在


图片:cemung_in_roate

技术分享图片:  cemung_out_roate

技术分享

效果截图

中间的黄色圆圈转动

技术分享



本文出自 “android旋转动画” 博客,请务必保留此出处http://7239441.blog.51cto.com/7229441/1700905

android运用旋转动画

标签:android

原文地址:http://7239441.blog.51cto.com/7229441/1700905

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!