
本文是在我的文章android图片处理,让图片变成圆形 的基础上继续写的,可以去看看,直接看也没关系,也能看懂
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 >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); }} 是不是很简单,运行效果如下:录制的有点问题,实际上是匀速地。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的android图片处理之让图片一直匀速旋转全部内容,希望文章能够帮你解决android图片处理之让图片一直匀速旋转所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)