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

Android 三種動(dòng)畫詳解及簡單實(shí)例

 更新時(shí)間:2017年04月18日 09:21:49   投稿:lqh  
這篇文章主要介紹了Android 三種動(dòng)畫詳解及簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下

Android 三種動(dòng)畫詳解

幀動(dòng)畫

一張張圖片不斷的切換,形成動(dòng)畫效果

在drawable目錄下定義xml文件,子節(jié)點(diǎn)為animation-list,在這里定義要顯示的圖片和每張圖片的顯示時(shí)長

<animation-list 
xmlns:android="http://schemas.android.com/apk/res/android" 
   android:oneshot="false">
      <item android:drawable="@drawable/g1" 
         android:duration="200" />
      <item android:drawable="@drawable/g2" 
         android:duration="200" />
      <item android:drawable="@drawable/g3" 、
         android:duration="200" />
    </animation-list>

在屏幕上播放幀動(dòng)畫

ImageView iv = (ImageView) findViewById(R.id.iv);
    //把動(dòng)畫文件設(shè)置為imageView的背景
    iv.setBackgroundResource(R.drawable.animations);
    AnimationDrawable ad = (AnimationDrawable)
    iv.getBackground();
    //播放動(dòng)畫    
    ad.start();

補(bǔ)間動(dòng)畫

  • 原形態(tài)變成新形態(tài)時(shí)為了過渡變形過程,生成的動(dòng)畫就叫補(bǔ)間動(dòng)畫,補(bǔ)間動(dòng)畫,只是一個(gè)動(dòng)畫效果,組件其實(shí)還在原來的位置上,xy沒有改變
  • 位移、旋轉(zhuǎn)、縮放、透明

位移:

  • 參數(shù)10指的是X的起點(diǎn)坐標(biāo),但不是指屏幕x坐標(biāo)為10的位置,而是imageview的 真實(shí)X + 10
  • 參數(shù)150指的是X的終點(diǎn)坐標(biāo),它的值是imageview的 真實(shí)X + 150
//創(chuàng)建為位移動(dòng)畫對象,設(shè)置動(dòng)畫的初始位置和結(jié)束位置
TranslateAnimation ta = new TranslateAnimation(10, 150, 20, 140);
  • x坐標(biāo)的起點(diǎn)位置,如果相對于自己,傳0.5f,那么起點(diǎn)坐標(biāo)就是 真實(shí)X + 0.5 * iv寬度
  • x坐標(biāo)的終點(diǎn)位置,如果傳入2,那么終點(diǎn)坐標(biāo)就是 真實(shí)X + 2 * iv的寬度
  • y坐標(biāo)的起點(diǎn)位置,如果傳入0.5f,那么起點(diǎn)坐標(biāo)就是 真實(shí)Y + 0.5 * iv高度
  • y坐標(biāo)的終點(diǎn)位置,如果傳入2,那么終點(diǎn)坐標(biāo)就是 真實(shí)Y + 2 * iv高度
 TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2);

動(dòng)畫播放相關(guān)的設(shè)置

    //設(shè)置動(dòng)畫持續(xù)時(shí)間
    ta.setDuration(2000);
    //動(dòng)畫重復(fù)播放的次數(shù)
    ta.setRepeatCount(1);
    //動(dòng)畫重復(fù)播放的模式
    ta.setRepeatMode(Animation.REVERSE);
    //動(dòng)畫播放完畢后,組件停留在動(dòng)畫結(jié)束的位置上
    ta.setFillAfter(true);
    //播放動(dòng)畫
    iv.startAnimation(ta);

縮放:

  • 參數(shù)0.1f表示動(dòng)畫的起始寬度是真實(shí)寬度的0.1倍
  • 參數(shù)4表示動(dòng)畫的結(jié)束寬度是真實(shí)寬度的4倍
  • 縮放的中心點(diǎn)在iv左上角
ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4);
  • 參數(shù)0.1f和4意義與上面相同
  • 改變縮放的中心點(diǎn):傳入的兩個(gè)0.5f,類型都是相對于自己,這兩個(gè)參數(shù)改變了縮放的中心點(diǎn)
  • 中心點(diǎn)x坐標(biāo) = 真實(shí)X + 0.5 * iv寬度
  • 中心點(diǎn)Y坐標(biāo) = 真實(shí)Y + 0.5 * iv高度
ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

透明:

0為完全透明,1為完全不透明

  AlphaAnimation aa = new AlphaAnimation(0, 0.5f);

旋轉(zhuǎn):

  • 20表示動(dòng)畫開始時(shí)的iv的角度
  • 360表示動(dòng)畫結(jié)束時(shí)iv的角度
  • 默認(rèn)旋轉(zhuǎn)的圓心在iv左上角
RotateAnimation ra = new RotateAnimation(20, 360);
  1. 20,360的意義和上面一樣
  2. 指定圓心坐標(biāo),相對于自己,值傳入0.5,那么圓心的x坐標(biāo):真實(shí)X + iv寬度 * 0.5
  3. 圓心的Y坐標(biāo):真實(shí)Y + iv高度 * 0.5
RotateAnimation ra = new RotateAnimation(20, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

所有動(dòng)畫一起飛

 //創(chuàng)建動(dòng)畫集合
    AnimationSet set = new AnimationSet(false);
    //往集合中添加動(dòng)畫
    set.addAnimation(aa);
    set.addAnimation(sa);
    set.addAnimation(ra);
    iv.startAnimation(set);

屬性動(dòng)畫

位移:

  1. 第一個(gè)參數(shù)target指定要顯示動(dòng)畫的組件
  2. 第二個(gè)參數(shù)propertyName指定要改變組件的哪個(gè)屬性
  3. 第三個(gè)參數(shù)values是可變參數(shù),就是賦予屬性的新的值
  4. 傳入0,代表x起始坐標(biāo):當(dāng)前x + 0
  5. 傳入100,代表x終點(diǎn)坐標(biāo):當(dāng)前x + 100
//具有g(shù)et、set方法的成員變量就稱為屬性
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "translationX", 0, 100) ;

縮放:

  • 第三個(gè)參數(shù)指定縮放的比例
  • 0.1是從原本高度的十分之一開始
  • 2是到原本高度的2倍結(jié)束
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "scaleY", 0.1f, 2);

透明:

透明度,0是完全透明,1是完全不透明

ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "alpha", 0.1f, 1);

旋轉(zhuǎn)

  1. rotation指定是順時(shí)針旋轉(zhuǎn)
  2. 20是起始角度
  3. 270是結(jié)束角度
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "rotation", 20, 270);
  1. 屬性指定為rotationX是豎直翻轉(zhuǎn)
  2. 屬性指定為rotationY是水平翻轉(zhuǎn)
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "rotationY", 20, 180);

可變參數(shù)

第三個(gè)參數(shù)可變參數(shù)可以傳入多個(gè)參數(shù),可以實(shí)現(xiàn)往回位移(旋轉(zhuǎn)、縮放、透明)

ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "translationX", 0, 70, 30, 100) ;

所有動(dòng)畫一起飛       

     //創(chuàng)建動(dòng)畫師集合
    AnimatorSet set = new AnimatorSet();
    //設(shè)置要播放動(dòng)畫的組件
    set.setTarget(bt);
    //所有動(dòng)畫有先后順序的播放
    //set.playSequentially(oa, oa2, oa3, oa4);
    //所有動(dòng)畫一起播放
    set.playTogether(oa, oa2, oa3, oa4);
    set.start();

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論