欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)簡單旋轉(zhuǎn)動(dòng)畫

 更新時(shí)間:2022年07月20日 10:02:45   作者:Android-kongqw  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡單旋轉(zhuǎn)動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)簡單旋轉(zhuǎn)動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下

核心方法

public void startAnimation(Animation animation)

執(zhí)行動(dòng)畫,參數(shù)可以是各種動(dòng)畫的對(duì)象,Animation的多態(tài),也可以是組合動(dòng)畫,后面會(huì)有。

2個(gè)參數(shù)的構(gòu)造方法

/**
?* Constructor to use when building a RotateAnimation from code.
?* Default pivotX/pivotY point is (0,0).
?*?
?* @param fromDegrees Rotation offset to apply at the start of the animation.
?* @param toDegrees Rotation offset to apply at the end of the animation.
?*/
public RotateAnimation(float fromDegrees, float toDegrees) {
? ? mFromDegrees = fromDegrees;
? ? mToDegrees = toDegrees;
? ? mPivotX = 0.0f;
? ? mPivotY = 0.0f;
}
  • 第一個(gè)參數(shù)是圖片旋轉(zhuǎn)的起始度數(shù)
  • 第二個(gè)參數(shù)是圖片旋轉(zhuǎn)結(jié)束的度數(shù)

用法

RotateAnimation ta = new RotateAnimation(0, 360);
// 設(shè)置動(dòng)畫播放的時(shí)間
ta.setDuration(1000);
// 開始播放動(dòng)畫
iv.startAnimation(ta);

效果

以圖片左上角為旋轉(zhuǎn)中心,順時(shí)針旋轉(zhuǎn)360度

4個(gè)參數(shù)的構(gòu)造方法

/**
? ? ?* Constructor to use when building a RotateAnimation from code
? ? ?*?
? ? ?* @param fromDegrees Rotation offset to apply at the start of the animation.
? ? ?* @param toDegrees Rotation offset to apply at the end of the animation.
? ? ?* @param pivotX The X coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the left edge.
? ? ?* @param pivotY The Y coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the top edge.
? ? ?*/
? ? public RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY) {
? ? ? ? mFromDegrees = fromDegrees;
? ? ? ? mToDegrees = toDegrees;

? ? ? ? mPivotXType = ABSOLUTE;
? ? ? ? mPivotYType = ABSOLUTE;
? ? ? ? mPivotXValue = pivotX;
? ? ? ? mPivotYValue = pivotY;
? ? ? ? initializePivotPoint();
? ? }
  • 頭兩個(gè)參數(shù)和上面兩個(gè)參數(shù)的構(gòu)造方法一樣,是開始和結(jié)束的角度
  • 后兩個(gè)參數(shù)是設(shè)置圖片的旋轉(zhuǎn)中心

用法

RotateAnimation ta = new RotateAnimation(0, 360, iv.getWidth() / 2, iv.getHeight() / 2);
// 設(shè)置動(dòng)畫播放的時(shí)間
ta.setDuration(1000);
// 開始播放動(dòng)畫
iv.startAnimation(ta);

效果

以圖片中心為旋轉(zhuǎn)中心,順時(shí)針旋轉(zhuǎn)360度

6個(gè)參數(shù)的構(gòu)造方法

/**
* Constructor to use when building a RotateAnimation from code
*?
* @param fromDegrees Rotation offset to apply at the start of the animation.
* @param toDegrees Rotation offset to apply at the end of the animation.
* @param pivotXType Specifies how pivotXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param pivotXValue The X coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the left edge. This value can either be an absolute number if pivotXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
* @param pivotYType Specifies how pivotYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param pivotYValue The Y coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the top edge. This value can either be an absolute number if pivotYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
*/
public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) {
? ?mFromDegrees = fromDegrees;
? ?mToDegrees = toDegrees;

? ?mPivotXValue = pivotXValue;
? ?mPivotXType = pivotXType;
? ?mPivotYValue = pivotYValue;
? ?mPivotYType = pivotYType;
? ?initializePivotPoint();
}

比4個(gè)參數(shù)的構(gòu)造方法多了第三個(gè)和第五個(gè)參數(shù),其他用法一樣,第三個(gè)和四五個(gè)參數(shù)分別設(shè)置第四個(gè)和第六個(gè)參數(shù)的類型,四個(gè)參數(shù)的構(gòu)造沒有設(shè)置,是默認(rèn)設(shè)置了Animation.ABSOLUTE類型

用法

// 創(chuàng)建旋轉(zhuǎn)的動(dòng)畫對(duì)象
RotateAnimation ta = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
// 設(shè)置動(dòng)畫播放的時(shí)間
ta.setDuration(1000);
// 開始播放動(dòng)畫
iv.startAnimation(ta);

效果

和上面一樣,以圖片中心為旋轉(zhuǎn)中心,順時(shí)針旋轉(zhuǎn)360度。

設(shè)置動(dòng)畫重復(fù)播放的次數(shù)的方法

/**
?* Sets how many times the animation should be repeated. If the repeat
?* count is 0, the animation is never repeated. If the repeat count is
?* greater than 0 or {@link #INFINITE}, the repeat mode will be taken
?* into account. The repeat count is 0 by default.
?*
?* @param repeatCount the number of times the animation should be repeated
?* @attr ref android.R.styleable#Animation_repeatCount
?*/
public void setRepeatCount(int repeatCount) {
? ? if (repeatCount < 0) {
? ? ? ? repeatCount = INFINITE;
? ? }
? ? mRepeatCount = repeatCount;
}

使用

sa.setRepeatCount(2);

一直重復(fù)

sa.setRepeatCount(Animation.INFINITE);

設(shè)置動(dòng)畫重復(fù)播放的模式的方法

/**
?* Defines what this animation should do when it reaches the end. This
?* setting is applied only when the repeat count is either greater than
?* 0 or {@link #INFINITE}. Defaults to {@link #RESTART}.?
?*
?* @param repeatMode {@link #RESTART} or {@link #REVERSE}
?* @attr ref android.R.styleable#Animation_repeatMode
?*/
public void setRepeatMode(int repeatMode) {
? ? mRepeatMode = repeatMode;
}

使用

sa.setRepeatMode(ScaleAnimation.REVERSE);

動(dòng)畫的監(jiān)聽

rotateAnimation.setAnimationListener(new AnimationListener() {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationStart(Animation animation) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub

? ? ? ? ? ? }

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationRepeat(Animation animation) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub

? ? ? ? ? ? }

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationEnd(Animation animation) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub

? ? ? ? ? ? }
?});

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android?Flutter實(shí)現(xiàn)評(píng)分組件的示例代碼

    Android?Flutter實(shí)現(xiàn)評(píng)分組件的示例代碼

    在很多應(yīng)用中,我們都需要收集用戶的評(píng)分,比如商品滿意度、配送滿意度、應(yīng)用使用體驗(yàn)等等。本文就利用flutter_rating_bar實(shí)現(xiàn)簡易的評(píng)分組件,感興趣的可以
    2022-11-11
  • android開發(fā)教程之時(shí)間對(duì)話框核心代碼

    android開發(fā)教程之時(shí)間對(duì)話框核心代碼

    這篇文章主要介紹了android的時(shí)間對(duì)話框核心代碼,需要的朋友可以參考下
    2014-04-04
  • Android開發(fā)中的Surface庫及用其制作播放器UI的例子

    Android開發(fā)中的Surface庫及用其制作播放器UI的例子

    這篇文章主要介紹了Android開發(fā)中的Surface庫及用其制作播放器界面的例子,利用SurfaceView和SurfaceHolder可以高效地繪制和控制圖形界面,需要的朋友可以參考下
    2016-04-04
  • android 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法

    android 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法

    下面小編就為大家?guī)硪黄猘ndroid 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • 分享Android中Toast的自定義使用

    分享Android中Toast的自定義使用

    Android中的Toast是一種簡易的消息提示框,toast提示框不能被用戶點(diǎn)擊,toast會(huì)根據(jù)用戶設(shè)置的顯示時(shí)間后自動(dòng)消失。本文將介紹Toast的自定義使用,下面一起來看看吧。
    2016-08-08
  • OpenGL Shader實(shí)現(xiàn)簡單轉(zhuǎn)場效果詳解

    OpenGL Shader實(shí)現(xiàn)簡單轉(zhuǎn)場效果詳解

    轉(zhuǎn)場效果常出現(xiàn)再視頻剪輯當(dāng)中,用于銜接兩段視頻片段切換的過渡效果。本文將介紹如何利用OpenGL Shader實(shí)現(xiàn)簡單的轉(zhuǎn)場效果,需要的小伙伴可以參考一下
    2022-02-02
  • 詳解Flutter掃碼識(shí)別二維碼內(nèi)容

    詳解Flutter掃碼識(shí)別二維碼內(nèi)容

    這篇文章主要介紹了Flutter掃碼識(shí)別二維碼內(nèi)容的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Android開發(fā)中常用的一些小技巧

    Android開發(fā)中常用的一些小技巧

    這篇文章主要介紹了Android開發(fā)中常用的一些小技巧,個(gè)人總結(jié)的一些常用方法和小技巧,需要的朋友可以參考下
    2015-02-02
  • android 禁止第三方apk安裝和卸載的方法詳解

    android 禁止第三方apk安裝和卸載的方法詳解

    這篇文章主要介紹了android 禁止第三方apk安裝和卸載,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Android組件之服務(wù)的詳解

    Android組件之服務(wù)的詳解

    這篇文章主要詳細(xì)介紹了Android組件之一的服務(wù),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08

最新評(píng)論