android圖片處理之讓圖片一直勻速旋轉_Android

來源:互聯網
上載者:User

本文是在我的文章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 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); }}

 是不是很簡單,運行效果如下:錄製的有點問題,實際上是勻速地。

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.