文章目录

        • 1、简介
        • 2、代码结构
        • 3、Activity_mani.xml 文件
        • 4、rotate.xml 文件
        • 5、MainActivity 文件

1、简介

2、代码结构

1)activity_main 文件 加载图片 和 按钮
2)rotate 是定义的属性动画
3)ManiActivity 文件是 功能 动画

3、Activity_mani.xml 文件

<?xml version="1.0" encoding="utf-8"?>            

4、rotate.xml 文件

<?xml version="1.0" encoding="utf-8"?>        

5、MainActivity 文件

package com.example.lum.myrotate;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.AnimationUtils;import android.view.animation.RotateAnimation;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private String TAG = "MainActivity: ";    private ImageView imageViewOne,imageViewTwo;    private Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        imageViewOne = (ImageView) findViewById(R.id.img_one_id);        imageViewTwo = (ImageView) findViewById(R.id.img_two_id);        button = (Button) findViewById(R.id.but_id);        button.setOnClickListener(this);    }    @Override    public void onClick(View v) {        switch (v.getId()){            case R.id.but_id:                Log.i(TAG,"开始旋转动画");                rotateFromXml();                rotateFromCode();                break;                default:                    break;        }    }    //通过代码进行旋转都规划设定    private void rotateFromCode() {        //创建AninationSet 对象        AnimationSet animationSet = new AnimationSet(true);        //创建 RotateAnimation 对象        RotateAnimation rotateAnimation = new RotateAnimation(0f,+360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);        //设置动画持续        rotateAnimation.setDuration(5000);        //动画插入器        rotateAnimation.setInterpolator(this,android.R.anim.decelerate_interpolator);        //添加到 AnimationSet        animationSet.addAnimation(rotateAnimation);        imageViewTwo.startAnimation(animationSet);    }    //通过xml 加载动画属性    private void rotateFromXml() {        //定义Animation对象        Animation animation = AnimationUtils.loadAnimation(this,R.anim.rotate);        imageViewOne.startAnimation(animation);    }}

文章参考:
《Android 典型技术模块开发详解》

本人郑重声明,本博客所编文章、图片版权归权利人持有,本博只做学习交流分享所用,不做任何商业用途。访问者可將本博提供的內容或服务用于个人学习、研究或欣赏,不得用于商业使用。同時,访问者应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人的合法权利;如果用于商业用途,须征得相关权利人的书面授权。若文章、图片的原作者不愿意在此展示內容,请及时通知在下,將及时予以刪除。

更多相关文章

  1. Phonegap获取imei (修改phonegap官方提供文件)
  2. Windows 8上搭建Cocos2d-x for Android的开发环境
  3. 一个简单的Android小实例
  4. Android显示GIF动画问题
  5. Android开发之如何在App间安全地共享文件(FileProvider详解)?
  6. 67-Flutter中高德地图插件的使用
  7. Android利用RotateAnimation实现旋转变化动画
  8. Android活动进出场动画
  9. android中配置文件property的用途以及使用

随机推荐

  1. Android的常用传感器
  2. Android中对Log日志文件的分析
  3. android应用安全——通信安全(android htt
  4. 开发可统计单词个数的Android驱动程序(1)
  5. Android(安卓)事件分发机制
  6. 打包Android程序—Android跟我学2.2
  7. android关于installLocation
  8. 在Android中使用Handler和Thread线程执行
  9. Android(安卓)cts all pass 全攻略
  10. Android(安卓)USB 开发详解