當前位置:首頁 » 安卓系統 » android旋轉圖片動畫

android旋轉圖片動畫

發布時間: 2022-06-25 21:05:54

❶ android 怎麼在輪播時實現多種動畫效果,如第一張到第二張漸變,第二張到第三張旋轉

Android系統自帶的一個多頁面管理控制項,它可以實現子界面的自動切換:

首先 需要為ViewFlipper加入View

(1) 靜態導入:在layout布局文件中直接導入

(2) 動態導入:addView()方法

ViewPlipper常用方法:

setInAnimation:設置View進入屏幕時候使用的動畫

setOutAnimation:設置View退出屏幕時候使用的動畫

showNext:調用該函數來顯示ViewFlipper裡面的下一個View

showPrevious:調用該函數來顯示ViewFlipper裡面的上一個View

setFlipInterval:設置View之間切換的時間間隔

startFlipping使用上面設置的時間間隔來開始切換所有的View,切換會循環進行

stopFlipping:停止View切換

講了這么多,那麼我們今天要實現的是什麼呢?

(1) 利用ViewFlipper實現圖片的輪播

(2) 支持手勢滑動的ViewFlipper

我們需要先准備幾張圖片:把圖片放進drawable中

創建兩個動畫:在res下面新建一個folder裡面新建兩個xml:

❷ 在android中,某圖片使用rotateanimation動畫,如何繞著這個圖片的左下角的進行旋轉

1、定義一個ImageView
定義一個ImageView是為了裝載圖片,其中的圖片將被rotate用來進行旋轉,其他View亦可。
資源文件為

復制代碼代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/infoOperating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/operating"
android:scaleType="center">
</ImageView>
</LinearLayout>

其中的android:src為圖片內容,可使用附件中的圖片。
java代碼為

復制代碼代碼如下:

ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating);

2、定義rotate旋轉效果
在res/anim文件夾下新建tip.xml文件,內容如下

復制代碼代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:ration="500"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%" />
</set>

含義表示從0到359度開始循環旋轉,0-359(若設置成360在停止時會出現停頓現象)度旋轉所用時間為500ms,旋轉中心距離view的左頂點為50%距離,距離view的上邊緣為50%距離,即正中心,具體每個含義見下面的具體屬性介紹。

java代碼為

復制代碼代碼如下:

Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);

setInterpolator表示設置旋轉速率。LinearInterpolator為勻速效果,Accelerateinterpolator為加速效果、DecelerateInterpolator為減速效果,具體可見下面android:interpolator的介紹。
a. 關於其中的屬性意義如下(紅色部分加以注意):
android:fromDegrees 起始的角度度數
android:toDegrees 結束的角度度數,負數表示逆時針,正數表示順時針。如10圈則比android:fromDegrees大3600即可
android:pivotX 旋轉中心的X坐標
浮點數或是百分比。浮點數表示相對於Object的左邊緣,如5; 百分比表示相對於Object的左邊緣,如5%; 另一種百分比表示相對於父容器的左邊緣,如5%p; 一般設置為50%表示在Object中心
android:pivotY 旋轉中心的Y坐標
浮點數或是百分比。浮點數表示相對於Object的上邊緣,如5; 百分比表示相對於Object的上邊緣,如5%; 另一種百分比表示相對於父容器的上邊緣,如5%p; 一般設置為50%表示在Object中心
android:ration 表示從android:fromDegrees轉動到android:toDegrees所花費的時間,單位為毫秒。可以用來計算速度。
android:interpolator表示變化率,但不是運行速度。一個插補屬性,可以將動畫效果設置為加速,減速,反復,反彈等。默認為開始和結束慢中間快,
android:startOffset 在調用start函數之後等待開始運行的時間,單位為毫秒,若為10,表示10ms後開始運行
android:repeatCount 重復的次數,默認為0,必須是int,可以為-1表示不停止
android:repeatMode 重復的模式,默認為restart,即重頭開始重新運行,可以為reverse即從結束開始向前重新運行。在android:repeatCount大於0或為infinite時生效
android:detachWallpaper 表示是否在壁紙上運行
android:zAdjustment 表示被animated的內容在運行時在z軸上的位置,默認為normal。
normal保持內容當前的z軸順序
top運行時在最頂層顯示
bottom運行時在最底層顯示
b. 運行速度
運行速度為運行時間(android:ration)除以運行角度差(android:toDegrees-android:fromDegrees),比如android:ration為1000,android:toDegrees為360,android:fromDegrees為0就表示1秒轉1圈。
c. 循環運行

復制代碼代碼如下:

android:fromDegrees="0"
android:toDegrees="360"
android:repeatCount="-1"

android:repeatCount="-1"即表示循環運行,配合上android:fromDegrees="0" android:toDegrees="360"表示不間斷
3、開始和停止旋轉
在操作開始之前調用

復制代碼代碼如下:

if (operatingAnim != null) {
infoOperatingIV.startAnimation(operatingAnim);
}

在操作完成時調用

復制代碼代碼如下:

infoOperatingIV.clearAnimation();

許多朋友不知道如何停止旋轉animation,所以強制設置rotate轉動多少圈表示操作,但卻無法與操作實際的進度匹配上,實際上只要如上代碼所示清除animation即可。
其他:
對於上面的轉動在橫屏(被設置為了不重繪activity)時會出現問題,即旋轉中心偏移,導致動畫旋轉偏離原旋轉中心。解決如下

復制代碼代碼如下:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) {
infoOperatingIV.clearAnimation();
infoOperatingIV.startAnimation(operatingAnim);
}
}

❸ android怎麼實現一張圖片旋轉幾秒後後自動換到另一張圖片

圖片旋轉使用動畫,設置動畫時間,旋轉完成後,設置另一張圖片

RotateAnimation 動畫,
RotateAnimation (float fromDegrees, float toDegrees, int
pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數說明:

float fromDegrees:旋轉的開始角度。
float toDegrees:旋轉的結束角度。
int
pivotXType:X軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotXValue:X坐標的伸縮值。
int
pivotYType:Y軸的伸縮模式,可以取值為ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotYValue:Y坐標的伸縮值。

❹ android怎麼實現圖片旋轉

可以使用RotateAnimation動畫實現,設定無限循環即可

代碼如下

{

ImageViewiv;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
iv=(ImageView)findViewById(R.id.image);
RotateAnimationanimation=newRotateAnimation(0,360);
animation.setDuration(100000);//設定轉一圈的時間
animation.setRepeatCount(Animation.INFINITE);//設定無限循環
animation.setRepeatMode(Animation.RESTART);
iv.startAnimation(animation);
}
}


也可以自定義view繼承於imageview,啟動一個線程,在while循環里設置view的旋轉角度


{

privatefloatmCurDegree=0;//當前旋轉角度
publicRotateView(Contextcontext,AttributeSetattrs){
super(context,attrs);
newThread(this).start();
}

@Override
protectedvoidonLayout(booleanchanged,intleft,inttop,intright,
intbottom){
super.onLayout(changed,left,top,right,bottom);
//設定旋轉中心
setPivotX(getMeasuredWidth()/2);
setPivotY(getMeasuredHeight()/2);
}

@Override
publicvoidrun(){
while(true){
setRotation(mCurDegree);
mCurDegree+=5;
postInvalidate();
SystemClock.sleep(16);
}
}
}

在布局文件里使用RotateView代替imageview即可

❺ Android 旋轉動畫

<rotate
android:fromDegrees="45"//起始旋轉的角度
android:toDegrees="89"//結束選裝後的角度
android:ration="500"//執行時間為500ms
android:pivotX="50%"//距離控制項左邊緣50%
android:pivotY="50%"//距離控制項上邊緣50%(與上邊結合就是控制項中心)
android:fillEnabled="true"
android:fillAfter="true"//動畫執行完後停留在執行完的狀態
/>

—————————————————————————————————————————

當然也可以通過代碼用animation實現

好久沒寫,應該是

RotateAnimationanimation=newRotateAnimation(0f,45f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(500);
view.setAnimation(animation);

❻ android 的動畫效果怎麼做

1. Tween Animation:通過對場景里的對象不斷做圖像變換(平移、縮放、旋轉)產生動畫效果,即是一種漸變動畫;
2. Frame Animation:順序播放事先做好的圖像,是一種畫面轉換動畫。
動畫類型
下面先來看看Android提供的動畫類型。Android的animation由四種類型組成
在XML文件中:
alpha 漸變透明度動畫效果
scale 漸變尺寸伸縮動畫效果
translate 畫面轉換位置移動動畫效果
rotate 畫面轉移旋轉動畫效果
在Java 源碼中定義了相應的類,可以使用這些類的方法來獲取和操作相應的屬性:
AlphaAnimation漸變透明度動畫效果
ScaleAnimation漸變尺寸伸縮動畫效果
TranslateAnimation畫面轉換位置移動動畫效果
RotateAnimation畫面轉移旋轉動畫效果

❼ android怎麼實現一張圖片以它的對角線進行翻轉的動畫

3.0以上,有個ObjectAnimator可以實現

給你個動畫集源代碼,裡面有各種android的動畫效果

其中有一個界面就有這個動畫

❽ 如何實現Rotate旋轉動畫的android源代碼

android源代碼之Rotate旋轉動畫
標簽為旋轉節點
Tween一共為我們提供了3種動畫渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 設置動畫渲染器為加速動畫(動畫播放中越來越快)
android:interpolator="@android:anim/decelerate_interpolator" 設置動畫渲染器為減速動畫(動畫播放中越來越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 設置動畫渲染器為先加速在減速(開始速度最快 逐漸減慢)
如果不寫的話 默認為勻速運動
android:fromDegrees="+360"設置動畫開始的角度
android:toDegrees="0"設置動畫結束的角度
這個動畫布局設置動畫將向左做360度旋轉加速運動。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
復制代碼
代碼實現
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋轉動畫按鈕**/
Button mButton0 = null;
/**向右旋轉動畫按鈕**/
Button mButton1 = null;
/**顯示動畫的ImageView**/
ImageView mImageView = null;
/**向左旋轉動畫**/
Animation mLeftAnimation = null;
/**向右旋轉動畫**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView對象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**載入向左與向右旋轉動畫**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋轉動畫**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋轉動畫**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}
學習更多關於android源代碼,可以查詢

❾ 安卓開發旋轉動畫實現的時候為什麼會刷新界面

Android 平台提供了兩類動畫,一類是 Tween 動畫,即通過對場景里的對象不斷做圖像變換(平移、縮放、旋轉)產生動畫效果;第二類是 Frame 動畫,即順序播放事先做好的圖像,跟電影類似。本文分析 Tween動畫的rotate實現旋轉效果。 在新浪微博客戶端中各個操作進行中時activity的右上角都會有個不停旋轉的圖標,類似刷新的效果,給用戶以操作中的提示。這種非模態的提示方式推薦使用,那麼下面就分享下如何實現這種效果吧 1、定義一個ImageView 定義一個ImageView是為了裝載圖片,其中的圖片將被rotate用來進行旋轉,其他View亦可。 資源文件為 Java代碼 xmlns:android="schemas/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> android:id="@+id/infoOperating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/operating" android:scaleType="center"> 其中的android:src為圖片內容,可使用附件中的圖片。 java代碼為 Java代碼 ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating); 2、定義rotate旋轉效果 在res/anim文件夾下新建tip.xml文件,內容如下 Java代碼 android:fromDegrees="0" android:toDegrees="359" android:ration="500" android:repeatCount="-1" android:pivotX="50%" android:pivotY="50%" /> 含義表示從0到359度開始循環旋轉,0-359(若設置成360在停止時會出現停頓現象)度旋轉所用時間為500ms,旋轉中心距離view的左頂點為50%距離,距離view的上邊緣為50%距離,即正中心,具體每個含義見下面的具體屬性介紹。 java代碼為 Java代碼 Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); setInterpolator表示設置旋轉速率。LinearInterpolator為勻速效果,Accelerateinterpolator為加速效果、DecelerateInterpolator為減速效果,具體可見下面android:interpolator的介紹。 a. 關於其中的屬性意義如下(紅色部分加以注意): android:fromDegrees 起始的角度度數 android:toDegrees 結束的角度度數,負數表示逆時針,正數表示順時針。如10圈則比android:fromDegrees大3600即可 android:pivotX 旋轉中心的X坐標 浮點數或是百分比。浮點數表示相對於Object的左邊緣,如5; 百分比表示相對於Object的左邊緣,如5%; 另一種百分比表示相對於父容器的左邊緣,如5%p; 一般設置為50%表示在Object中心 android:pivotY 旋轉中心的Y坐標 浮點數或是百分比。浮點數表示相對於Object的上邊緣,如5; 百分比表示相對於Object的上邊緣,如5%; 另一種百分比表示相對於父容器的上邊緣,如5%p; 一般設置為50%表示在Object中心 android:ration 表示從android:fromDegrees轉動到android:toDegrees所花費的時間,單位為毫秒。可以用來計算速度。 android:interpolator表示變化率,但不是運行速度。一個插補屬性,可以將動畫效果設置為加速,減速,反復,反彈等。默認為開始和結束慢中間快, android:startOffset 在調用start函數之後等待開始運行的時間,單位為毫秒,若為10,表示10ms後開始運行 android:repeatCount 重復的次數,默認為0,必須是int,可以為-1表示不停止 android:repeatMode 重復的模式,默認為restart,即重頭開始重新運行,可以為reverse即從結束開始向前重新運行。在android:repeatCount大於0或為infinite時生效 android:detachWallpaper 表示是否在壁紙上運行 android:zAdjustment 表示被animated的內容在運行時在z軸上的位置,默認為normal。 normal保持內容當前的z軸順序 top運行時在最頂層顯示 bottom運行時在最底層顯示 b. 運行速度 運行速度為運行時間(android:ration)除以運行角度差(android:toDegrees-android:fromDegrees),比如android:ration為1000,android:toDegrees為360,android:fromDegrees為0就表示1秒轉1圈。 c. 循環運行 Java代碼 android:fromDegrees="0" android:toDegrees="360" android:repeatCount="-1" android:repeatCount="-1"即表示循環運行,配合上android:fromDegrees="0" android:toDegrees="360"表示不間斷 3、開始和停止旋轉 在操作開始之前調用 Java代碼 if (operatingAnim != null) { infoOperatingIV.startAnimation(operatingAnim); } 在操作完成時調用 Java代碼 infoOperatingIV.clearAnimation(); 許多朋友不知道如何停止旋轉animation,所以強制設置rotate轉動多少圈表示操作,但卻無法與操作實際的進度匹配上,實際上只要如上代碼所示清除animation即可。 其他: 對於上面的轉動在橫屏(被設置為了不重繪activity)時會出現問題,即旋轉中心偏移,導致動畫旋轉偏離原旋轉中心。解決如下 Java代碼 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) { infoOperatingIV.clearAnimation(); infoOperatingIV.startAnimation(operatingAnim); } }

❿ android中怎麼定義旋轉動畫的旋轉速度

android源代碼之Rotate旋轉動畫
標簽為旋轉節點
Tween一共為我們提供了3種動畫渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 設置動畫渲染器為加速動畫(動畫播放中越來越快)
android:interpolator="@android:anim/decelerate_interpolator" 設置動畫渲染器為減速動畫(動畫播放中越來越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 設置動畫渲染器為先加速在減速(開始速度最快 逐漸減慢)
如果不寫的話 默認為勻速運動
android:fromDegrees="+360"設置動畫開始的角度
android:toDegrees="0"設置動畫結束的角度
這個動畫布局設置動畫將向左做360度旋轉加速運動。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
復制代碼
代碼實現
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋轉動畫按鈕**/
Button mButton0 = null;
/**向右旋轉動畫按鈕**/
Button mButton1 = null;
/**顯示動畫的ImageView**/
ImageView mImageView = null;
/**向左旋轉動畫**/
Animation mLeftAnimation = null;
/**向右旋轉動畫**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView對象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**載入向左與向右旋轉動畫**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋轉動畫**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋轉動畫**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}

熱點內容
磁碟禁止訪問 發布:2024-04-25 22:53:48 瀏覽:286
多線程ftp上傳 發布:2024-04-25 22:41:36 瀏覽:114
phpqrcode 發布:2024-04-25 22:41:36 瀏覽:32
桂平上網密碼是多少 發布:2024-04-25 22:32:10 瀏覽:574
open函數c語言 發布:2024-04-25 21:47:42 瀏覽:406
簡訊刪除後怎麼找伺服器 發布:2024-04-25 21:15:06 瀏覽:388
查ip地址伺服器數量 發布:2024-04-25 20:49:48 瀏覽:620
安卓手機單核性能為什麼不高 發布:2024-04-25 20:48:07 瀏覽:56
群暉php 發布:2024-04-25 20:00:35 瀏覽:884
怎麼查看我的wifi密碼 發布:2024-04-25 18:54:43 瀏覽:757