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);
}
}
是不是很簡(jiǎn)單,運(yùn)行效果如下:錄制的有點(diǎn)問題,實(shí)際上是勻速地。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android下拉刷新SwipeRefreshLayout控件使用方法
這篇文章主要介紹了Android下拉刷新SwipeRefreshLayout控件使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
Android 自定義View實(shí)現(xiàn)多節(jié)點(diǎn)進(jìn)度條功能
這篇文章主要介紹了Android 自定義View實(shí)現(xiàn)多節(jié)點(diǎn)進(jìn)度條,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
Android數(shù)據(jù)庫中事務(wù)操作方法之銀行轉(zhuǎn)賬示例
這篇文章主要介紹了Android數(shù)據(jù)庫中事務(wù)操作方法之銀行轉(zhuǎn)賬,以具體的銀行轉(zhuǎn)賬為例分析了Android數(shù)據(jù)庫操作中事務(wù)的使用與回滾相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
Flutter實(shí)現(xiàn)紅包動(dòng)畫效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Flutter實(shí)現(xiàn)紅包的動(dòng)畫效果,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下2023-06-06
Android高仿京東垂直循環(huán)滾動(dòng)新聞欄
通過自定義的LinearLayout,并且textView能夠循環(huán)垂直滾動(dòng),而且條目可以點(diǎn)擊,顯示區(qū)域最多顯示2個(gè)條目,并且還有交替的屬性垂直移動(dòng)的動(dòng)畫效果,通過線程來控制滾動(dòng)的實(shí)現(xiàn)2016-03-03

