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

Android?縮放動畫?ScaleAnimation的使用小結(jié)

 更新時間:2024年03月25日 15:02:54   作者:星月黎明  
ScaleAnimation即縮放動畫,應(yīng)用場景特別多,比如常見的隱藏菜單點擊顯示,這篇文章主要介紹了Android?縮放動畫?ScaleAnimation的使用小結(jié),需要的朋友可以參考下

什么是ScaleAnimation

ScaleAnimation即縮放動畫,應(yīng)用場景特別多,比如常見的隱藏菜單點擊顯示

下面我分兩種方式來介紹ScaleAnimation如何使用。

1. xml文件形式

文件名:anim_scale_in.xml
效果:呈現(xiàn)view放大顯示效果
源碼:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="1000"
        android:fillAfter="true"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

屬性解釋:
interpolator:動畫插入器,該功能在xml里設(shè)置貌似無效,需在代碼中加
fromXScale:從自身x軸長度多少倍開始縮放,如:fromXScale= 0.5表示從自身X軸長度0.5倍開始縮放
toXScale:縮放到自身x軸長度多少倍結(jié)束,如:toXScale = 2.0表示x軸縮放到自身x軸長度2倍結(jié)束
上面兩條意思就是:該view的x軸從自身x軸長度的0.5倍開始縮放到自身x軸長度的2倍結(jié)束
fromYScale:從自身y軸長度多少倍開始縮放,如:fromYScale= 0.5表示從自身y軸長度0.5倍開始縮放
toYScale:縮放到自身y軸長度多少倍結(jié)束,如:toYScale = 2.0表示x軸縮放到自身y軸長度2倍結(jié)束
pivotX:動畫相對于控件X坐標的開始位置
pivotY:動畫相對于控件Y坐標的開始位置
如:pivotX = 50%,pivotY = 50% 表示從該控件的中心開始縮放

   //表示控件左下角開始
   android:pivotX="0"
   android:pivotY="100%"
   //表示控件左上角開始
   android:pivotX="0"
   android:pivotY="0"
   //表示控件右下角開始
    android:pivotX="100%"
    android:pivotY="100%"
   //表示控件右上角開始
   android:pivotX="100%"
   android:pivotY="0"
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="1000"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0" />
</set>

OK,現(xiàn)在有了xml布局文件,我們需要用Java代碼讓他工作起來,如下;

 /**
     * 縮放變大動畫
     *
     * @param context
     * @param view 目標view
     */
    public static void startScaleInAnim(Context context, View view) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.anim_scale_in);
        if (view != null)
            view.startAnimation(animation);
    }
    /**
     * 縮放縮小動畫
     *
     * @param context
     * @param view 目標view
     */
    public static void startScaleOutAnim(Context context, View view) {
        Animation animation = AnimationUtils.loadAnimation(context, R.anim.anim_scale_out);
        if (view != null)
            view.startAnimation(animation);
    }

我單獨封裝在一個動畫工具類中,哪里需要就哪里調(diào)用。

下面看看代碼的執(zhí)行效果:

縮放同時還可以添加透明度變化,如下:

放大+淡入:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="1000"
        android:fillAfter="true"
        android:fillEnabled="true"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />
    <!--同時配置淡入功能-->
    <alpha
        android:duration="700"
        android:fillAfter="true"
        android:fromAlpha="0"
        android:toAlpha="1" />
</set>

縮小+淡出

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="1000"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0" />
    <!--同時配置淡出功能-->
    <alpha
        android:duration="700"
        android:fillAfter="true"
        android:fromAlpha="1"
        android:toAlpha="0" />
</set>

效果如下:

下拉菜單顯示與收回,效果:

顯示:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"
        android:fromXScale="1.0"
        android:fromYScale="0"
        android:pivotX="100%"
        android:pivotY="0"
        android:toXScale="1.0"
        android:toYScale="1.0" />
    <!--同時配置淡入功能-->
    <alpha
        android:duration="300"
        android:fillAfter="true"
        android:fromAlpha="0"
        android:toAlpha="1" />
</set>

收起:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="300"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="100%"
        android:pivotY="0"
        android:toXScale="1.0"
        android:toYScale="0" />
    <!--同時配置淡出功能-->
    <alpha
        android:duration="300"
        android:fillAfter="true"
        android:fromAlpha="1"
        android:toAlpha="0" />
</set>

效果:

縮放下拉與收回效果:

顯示:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="200"
        android:fillAfter="true"
        android:fillEnabled="true"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="100%"
        android:pivotY="0"
        android:toXScale="1.0"
        android:toYScale="1.0" />
    <!--同時配置淡入功能-->
    <alpha
        android:duration="200"
        android:fillAfter="true"
        android:fromAlpha="0"
        android:toAlpha="1" />
</set>

收起:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="200"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="100%"
        android:pivotY="0"
        android:toXScale="0"
        android:toYScale="0" />
    <!--同時配置淡出功能-->
    <alpha
        android:duration="200"
        android:fillAfter="true"
        android:fromAlpha="1"
        android:toAlpha="0" />
</set>

效果:

類似游戲按鈕的按下放大再還原效果:

  public static void animScaleIn(View view){
        //縮放動畫
        ScaleAnimation animation = new ScaleAnimation(1,1.2f,1,1.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        animation.setDuration(100);
        animation.setFillAfter(true);
        animation.setRepeatMode(Animation.REVERSE);
        animation.setRepeatCount(1);
        //透明度動畫
        AlphaAnimation animation1 = new AlphaAnimation(1,0.8f);
        animation1.setDuration(100);
        animation1.setRepeatCount(1);
        animation1.setRepeatMode(Animation.REVERSE);
        animation1.setFillAfter(true);
        //裝入AnimationSet中
        AnimationSet set = new AnimationSet(true);
        set.addAnimation(animation);
        set.addAnimation(animation1);
        if (view != null)
        view.startAnimation(set);
    }

效果如下:

備注:由于我的圖片是導(dǎo)出視頻再用PS轉(zhuǎn)換成的gif,故效率上有所損失,實際動畫效果和速度比圖片的快。

到此這篇關(guān)于Android 縮放動畫 ScaleAnimation的文章就介紹到這了,更多相關(guān)Android ScaleAnimation內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android學(xué)習(xí)之Span的使用方法詳解

    Android學(xué)習(xí)之Span的使用方法詳解

    這篇文章主要為大家詳細介紹了Android中各種Span類的使用方法,文中的示例代碼講解詳細,對我們學(xué)習(xí)Android有一定的幫助,需要的可以參考一下
    2022-06-06
  • Android開發(fā)App啟動流程與消息機制詳解

    Android開發(fā)App啟動流程與消息機制詳解

    這篇文章主要為大家介紹了Android開發(fā)App啟動流程與消息機制詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Android 為ListView添加分段標頭的方法

    Android 為ListView添加分段標頭的方法

    下面小編就為大家?guī)硪黄狝ndroid 為ListView添加分段標頭的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android WebView實現(xiàn)截長圖功能

    Android WebView實現(xiàn)截長圖功能

    這篇文章主要為大家詳細介紹了Android截長圖的一種實現(xiàn)方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android 使用Vitamio打造自己的萬能播放器(6)——在線播放(播放列表)

    Android 使用Vitamio打造自己的萬能播放器(6)——在線播放(播放列表)

    本文主要介紹Android Vitamino在線播放列表,這里給大家提供效果圖和實例代碼以便大家參考學(xué)習(xí),希望能幫助開發(fā)Android視頻播放的朋友
    2016-07-07
  • 如何利用matrix實現(xiàn)圖片倒影效果

    如何利用matrix實現(xiàn)圖片倒影效果

    利用matrix可以實現(xiàn)各種圖片的特效,比如圖片的旋轉(zhuǎn)、縮放、移動,甚至是圖片倒影效果,這篇文章為大家介紹了matrix實現(xiàn)圖片倒影的代碼,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android隱藏手機底部虛擬按鍵的方法

    Android隱藏手機底部虛擬按鍵的方法

    這篇文章主要為大家詳細介紹了Android隱藏手機底部虛擬按鍵的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android 讀寫文件方法匯總

    Android 讀寫文件方法匯總

    以下是對Android中讀寫文件的方法進行了匯總介紹,需要的朋友可以過來參考下
    2013-07-07
  • Android自定義view之太極圖的實現(xiàn)教程

    Android自定義view之太極圖的實現(xiàn)教程

    這篇文章主要給大家介紹了關(guān)于Android自定義view之太極圖的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 說說在Android如何使用服務(wù)(Service)的方法

    說說在Android如何使用服務(wù)(Service)的方法

    這篇文章主要介紹了說說在Android如何使用服務(wù)(Service)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06

最新評論