幀動畫,補間動畫,和屬性動畫

2021-07-16 18:52:14 字數 2751 閱讀 6013

幀動畫:frameanimation

多張快速切換,形成動畫效果

幀動畫使用xml定義.

建立乙個folder在res下,然後定義乙個xml檔案,根節點是animation——list.

將素材複製到drawable_hdpi資料夾下作為資源id.

""

android:oneshot=

"true"

>

"@drawable/g1" android:duration

="200"

/>

"@drawable/g2" android:duration

="200"

/>

//資源文drawable, 持續時間。

>

xml定義好之後,要將檔案顯示在imageview中。

步驟: 定義乙個imageview元件通過findviewbyid找到。

2,設定imageview的背景資源 iv.setbackgroundresource(r.drawable.定義的xml檔案)

3,然後在獲取background強轉成animationdrawable; animationdrawable ad = (animationdrawable) iv.getbackground();

4,開始幀動畫的動作。 ad.start();

dmeo:

package com.zh.frameanimation;

import android.graphics.drawable.animationdrawable;

import android.os.bundle;

import android.view.menu;

import android.view.menuitem;

import android.widget.imageview;

public

class

mainactivity

extends

activity

}

animation.relative_to_self:型別是相對於自己。

animation.relative_to_self, 1 x的起始位置是;

iv的真實位置是iv的真實x+1*iv的寬。(x+一倍自己的寬度iv.getwidth)

animation.relative_to_self, 0.5f, animation.relative_to_self, 2);

y軸方向;y軸的起始位置是 iv 的y軸的真實位置是:y+0.5倍的iv的高度;

結束位置是: 2倍iv的高度+y軸的位置。

(x,y可以為負數從相反的方向開始)。

設定重複的模式:相反的reverse

ta.setrepeatmode(animation.reverse);

//relative_to_parent 這個是相對于父元素來說。

demo:

public

void

translate(view v)

縮放:scale

//獲得縮放動畫物件。(預設不寫縮放中心的話是左上角)

scaleanimation sa = new scaleanimation(0.5f, 2, 0.1f, 3, iv.getwidth() / 2, iv.getheight() / 2); //縮放的開始位置和結束位置,還有縮放的

x座標的開始位置; x軸方向: x的真實起始位置是 x+0.5倍的iv的寬度,

2:表示x座標縮放的結束位置

* 2 * iv寬

iv.getwidth() / 2:表示縮放點的x座標

* iv的真實x + iv.getwidth() / 2

3、設定縮放還有乙個特性;

sa.setfillafter(true); //設定縮放的填充結束(也就是設定保持縮放結束後的最後的位置)。

public

void

scale1(view v)

縮放相對於自己的:

scaleanimation sa = new scaleanimation(0.5f, 2, 0.1f, 3,

animation.relative_to_self, 0.5f, animation.relative_to_self, 0.5f);

animation.relative_to_self, 0.5f:表示縮放點的x座標

* iv的真實x + 0.5 * iv寬

設定透明度:alpha;

alphaanimation al = new alphaanimation(fromalpha, toalpha) (透明度動畫)transparent :全透明的。

0:全透明; 1:完全不透明。

public

void

alpha(view v)

旋轉動畫:rotate;

rotateanimation ra = new rotateanimation(fromdegrees, todegrees, pivotx, pivoty) 從哪個中心點旋轉的角度範圍。

public void rotate(view v)
public

void

fly(view v)

android 動畫1 動畫補間動畫和幀動畫

透明方式 方式 animation alphaanimation new alphaanimation 0.0f,1.0f 載入 動畫資源檔案 animation animation animationutils.loadanimation this,r.anim.alpha anim imagev...

樣式和主題 幀動畫 補間動畫

name custom theme name android background ff0 item style name tongyicolor name android textcolor 00f item style name textview custom name android text...

Android補間動畫 逐幀動畫

逐幀動畫 補間動畫補間動畫補間動畫 分為四種 1.透明度變化 2.旋轉 3.平移 4.放大縮小透明度變化 步驟 1.new alphaanimation fromalpha,toalpha 1.fromalpha 透明度的初始值 0.0f 1.0f之間 2.toalpha 結束時的透明度的值 0.0...