• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
秋天不落叶-
帮助1

本文是在我的文章android图片处理,让图片变成圆形 的基础上继续写的,可以去看看,直接看也没关系,也能看懂 

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

  1.  
    <?xml version="1.0" encoding="utf-8"?>
  2.  
    <set xmlns:android="http://schemas.android.com/apk/res/android" >
  3.  
     
  4.  
    <rotate
  5.  
    android:duration="5000"
  6.  
    android:fromDegrees="0"
  7.  
    android:pivotX="50%"
  8.  
    android:pivotY="50%"
  9.  
    android:repeatCount="-1"
  10.  
    android:repeatMode="restart"
  11.  
    android:toDegrees="360" />
  12.  
     
  13.  
    </set>

 具体含义是:

duration:时间</span>

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

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

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

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

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

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

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

  1.  
    </
  2.  
    xmlns:tools="http://schemas.android.com/tools"
  3.  
    android:layout_width="match_parent"
  4.  
    android:layout_height="match_parent"
  5.  
    android:background="#ff00ff"
  6.  
    >
  7.  
     
  8.  
    <androidx.appcompat.widget.AppCompatImageView
  9.  
    android:id="@ id/imageview"
  10.  
    android:layout_width="100dp"
  11.  
    android:layout_height="100dp"
  12.  
    android:layout_centerInParent="true"
  13.  
    android:src="@drawable/control_image"
  14.  
    />
  15.  
    </RelativeLayout>
学新通

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

  1.  
    import android.os.Bundle;
  2.  
    import android.view.animation.Animation;
  3.  
    import android.view.animation.AnimationUtils;
  4.  
    import android.view.animation.LinearInterpolator;
  5.  
    import android.widget.ImageView;
  6.  
     
  7.  
    public class MainActivity extends Activity {
  8.  
     
  9.  
    @Override
  10.  
    protected void onCreate(Bundle savedInstanceState) {
  11.  
    super.onCreate(savedInstanceState);
  12.  
    setContentView(R.layout.activity_main);
  13.  
     
  14.  
    ImageView imageView = (ImageView) findViewById(R.id.imageview);
  15.  
    //动画
  16.  
    Animation animation = AnimationUtils.loadAnimation(this, R.anim.img_animation);
  17.  
    LinearInterpolator lin = new LinearInterpolator();//设置动画匀速运动
  18.  
    animation.setInterpolator(lin);
  19.  
    imageView.startAnimation(animation);
  20.  
    }
  21.  
     
  22.  
    }
学新通

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgibeeb
系列文章
更多 icon
同类精品
更多 icon
继续加载