当前位置: 移动技术网 > IT编程>移动开发>Android > android图片处理之让图片一直匀速旋转

android图片处理之让图片一直匀速旋转

2019年07月24日  | 移动技术网IT编程  | 我要评论

机翼测风装置,外围应用配置器,christy mack 种子

本文是在我的文章 的基础上继续写的,可以去看看,直接看也没关系,也能看懂 

1、首先在res文件夹下创建一个名字为anim的文件夹,名字不要写错 
2、在anim里面创建一个xlm文件:img_animation.xml,这个名字随便写都可以,注意不要大写,里面的代码如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

 <rotate
 android:duration="5000"
 android:fromdegrees="0"
 android:pivotx="50%"
 android:pivoty="50%"
 android:repeatcount="-1"
 android:repeatmode="restart"
 android:todegrees="360" />

</set>

 具体含义是:

duration:时间</span>

fromdegrees="0":  从几度开始转</span>t

odegrees="360" : 旋转多少度</span>       

pivotx="50%:旋转中心距离view的左顶点为50%距离,

pivoty="50%: 距离view的上边缘为50%距离

repeatcount="-1":重复次数,-1为一直重复

repeatmode="restart":重复模式,restart从头开始重复

布局文件代码没变,依旧是:放一个控件就行了

</
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#ff00ff"
 >

<com.example.circleimageview.circleimageview 
 android:id="@+id/imageview"
 android:layout_width="100dp"
 android:layout_height="100dp"
 android:layout_centerinparent="true"
 android:src="@drawable/control_image"
 />
</relativelayout>

你也可以写成一个普通的控件都可以实现旋转

复制代码 代码如下:
<span style="font-family: arial, helvetica, sans-serif;">package com.example.circleimageview;</span>import android.app.activity;

import android.os.bundle;
import android.view.animation.animation;
import android.view.animation.animationutils;
import android.view.animation.linearinterpolator;
import android.widget.imageview;

public class mainactivity extends activity {

 @override
 protected void oncreate(bundle savedinstancestate) {
 super.oncreate(savedinstancestate);
 setcontentview(r.layout.activity_main);
 
 imageview imageview = (imageview) findviewbyid(r.id.imageview);
 //动画
  animation animation = animationutils.loadanimation(this, r.anim.img_animation);
 linearinterpolator lin = new linearinterpolator();//设置动画匀速运动
 animation.setinterpolator(lin);
 imageview.startanimation(animation);
 }

}

 是不是很简单,运行效果如下:录制的有点问题,实际上是匀速地。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网