android圖片處理之讓圖片一直勻速旋轉(zhuǎn)
本文是在我的文章android圖片處理,讓圖片變成圓形 的基礎(chǔ)上繼續(xù)寫的,可以去看看,直接看也沒關(guān)系,也能看懂
1、首先在res文件夾下創(chuàng)建一個(gè)名字為anim的文件夾,名字不要寫錯(cuò)
2、在anim里面創(chuàng)建一個(gè)xlm文件:img_animation.xml,這個(gè)名字隨便寫都可以,注意不要大寫,里面的代碼如下:
<?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:時(shí)間</span>
fromDegrees="0": 從幾度開始轉(zhuǎn)</span>t
oDegrees="360" : 旋轉(zhuǎn)多少度</span>
pivotX="50%:旋轉(zhuǎn)中心距離view的左頂點(diǎn)為50%距離,
pivotY="50%: 距離view的上邊緣為50%距離
repeatCount="-1":重復(fù)次數(shù),-1為一直重復(fù)
repeatMode="restart":重復(fù)模式,restart從頭開始重復(fù)
布局文件代碼沒變,依舊是:放一個(gè)控件就行了
</ 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>
你也可以寫成一個(gè)普通的控件都可以實(shí)現(xiàn)旋轉(zhuǎn)
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); //動(dòng)畫 Animation animation = AnimationUtils.loadAnimation(this, R.anim.img_animation); LinearInterpolator lin = new LinearInterpolator();//設(shè)置動(dòng)畫勻速運(yùn)動(dòng) animation.setInterpolator(lin); imageView.startAnimation(animation); } }
是不是很簡單,運(yùn)行效果如下:錄制的有點(diǎn)問題,實(shí)際上是勻速地。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 加載assets中的資源文件實(shí)例代碼
這篇文章主要介紹了Android 加載assets中的資源文件實(shí)例代碼的相關(guān)資料,這里附有實(shí)例代碼,需要的朋友可以參考下2017-01-01Android開發(fā)之資源目錄assets與res/raw的區(qū)別分析
這篇文章主要介紹了Android開發(fā)之資源目錄assets與res/raw的區(qū)別,結(jié)合實(shí)例形式分析了Android開發(fā)中資源目錄assets與res/raw的具體功能、使用方法與區(qū)別,需要的朋友可以參考下2016-01-01Android使用TextInputLayout創(chuàng)建登陸頁面
這篇文章主要為大家詳細(xì)介紹了Android使用TextInputLayout創(chuàng)建登陸頁面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10Android studio實(shí)現(xiàn)簡單的計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)簡單的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03Listview中Button搶占焦點(diǎn)的解決方法
在程序開發(fā)中經(jīng)常見到listview button搶占焦點(diǎn)的問題,怎么回事什么原因呢?下面小編給大家?guī)砹薒istview中Button搶占焦點(diǎn)的解決方法,感興趣的朋友一起看下吧2016-08-08Android Socket接口實(shí)現(xiàn)即時(shí)通訊實(shí)例代碼
這篇文章主要介紹了Android Socket接口實(shí)現(xiàn)即時(shí)通訊實(shí)例代碼的相關(guān)資料,這里對通訊知識進(jìn)行了詳細(xì)介紹,并用Socket 接口實(shí)現(xiàn)通訊實(shí)例,需要的朋友可以參考下2016-12-12Flutter?將Dio請求轉(zhuǎn)發(fā)原生網(wǎng)絡(luò)庫的實(shí)現(xiàn)方案
這篇文章主要介紹了Flutter?將Dio請求轉(zhuǎn)發(fā)原生網(wǎng)絡(luò)庫,需要注意添加NativeNetInterceptor,如果有多個(gè)攔截器,例如LogInterceptors等等,需要將NativeNetInterceptor放到最后,需要的朋友可以參考下2022-05-05RecyclerView實(shí)現(xiàn)插入和刪除
這篇文章主要為大家詳細(xì)介紹了RecyclerView實(shí)現(xiàn)插入和刪除,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android Studio3.6中的View Binding初探及用法區(qū)別
這篇文章主要介紹了Android 中的View Binding初探及用法區(qū)別,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03