教你實現(xiàn)別人家的動畫3(淘寶,簡書動畫效果)

之前的文章都寫上csdn上,主要覺得簡書是分享文字的地方,最近發(fā)現(xiàn)關(guān)注我的開發(fā)專題人挺多的,就打算把這篇技術(shù)文章也發(fā)下簡書上吧,希望對一些朋友有幫助。
前2篇的地址 http://blog.csdn.net/tiankong1206/article/details/44901601
http://blog.csdn.net/tiankong1206/article/details/44947495
有興趣也可以去看看。

這篇文章我們來實現(xiàn)個稍微簡單點的動畫效果
每天在iphone上用淘寶和簡書發(fā)現(xiàn)他們有個共同的彈出效果(ios自帶的?),今天我們就來看看他們吧

這里寫圖片描述
這里寫圖片描述
這里寫圖片描述
這里寫圖片描述

好吧 我不知道怎么錄屏ios手機動態(tài)gif
沒關(guān)系,看我們實現(xiàn)后的效果就可以大概明白了。


這里寫圖片描述
這里寫圖片描述

ok 看完了效果圖 我們還是老規(guī)矩,首先來簡單分析下。

  • 首先有2個視圖,一個是主內(nèi)容視圖,第二個視圖有點類似popopWindow,它默認是不顯示的
  • 第一個動畫,popopWindow從下面彈出的時候,window的動畫很簡單,就是從下面移動出來顯示。主視圖的動畫也不難,包含x,y比例縮小,半透明,還有一個傾斜的效果
  • 第二個動畫就很明了,和第一個相反就ok了

分析下來發(fā)現(xiàn)挺簡單的,就是scale,alpha,translation幾個普通動畫組合
好了,開始碼代碼了
首先是布局文件,很簡單,里面就2個LinerLayout,各自包含一個按鈕。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/black">
    //主視圖
    <LinearLayout
        android:id="@+id/first_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical">
        <Button
            android:id="@+id/btn_anim3_show"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="show"/>
        </LinearLayout>
     //彈出框,默認不顯示
    <LinearLayout
        android:id="@+id/second_view"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@color/blue"
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:visibility="invisible">

        <Button
            android:id="@+id/btn_anim3_hidden"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="hidden"/>
        </LinearLayout>
</RelativeLayout>

接下來是第一個動畫,彈出框顯示時候的動畫,都是屬性動畫常見的動畫,沒有特別的。

//firstView是主視圖,secondView是popopWindow
private void initShowAnim(){
        ObjectAnimator fViewScaleXAnim=ObjectAnimator.ofFloat(firstView,"scaleX",1.0f,0.8f);
        fViewScaleXAnim.setDuration(350);
        ObjectAnimator fViewScaleYAnim=ObjectAnimator.ofFloat(firstView,"scaleY",1.0f,0.8f);
        fViewScaleYAnim.setDuration(350);
        ObjectAnimator fViewAlphaAnim=ObjectAnimator.ofFloat(firstView,"alpha",1.0f,0.5f);
        fViewAlphaAnim.setDuration(350);
        ObjectAnimator fViewRotationXAnim = ObjectAnimator.ofFloat(firstView, "rotationX", 0f, 10f);
        fViewRotationXAnim.setDuration(200);
        ObjectAnimator fViewResumeAnim = ObjectAnimator.ofFloat(firstView, "rotationX", 10f, 0f);
        fViewResumeAnim.setDuration(150);
        fViewResumeAnim.setStartDelay(200);
        ObjectAnimator fViewTransYAnim=ObjectAnimator.ofFloat(firstView,"translationY",0,-0.1f* fHeight);
        fViewTransYAnim.setDuration(350);
        ObjectAnimator sViewTransYAnim=ObjectAnimator.ofFloat(secondView,"translationY",sHeight,0);
        sViewTransYAnim.setDuration(350);
        sViewTransYAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                secondView.setVisibility(View.VISIBLE);
            }
        });
        showAnim=new AnimatorSet();
        showAnim.playTogether(fViewScaleXAnim,fViewRotationXAnim,fViewResumeAnim,fViewTransYAnim,fViewAlphaAnim,fViewScaleYAnim,sViewTransYAnim);
    }

第二個動畫和第一個動畫相反,就不貼代碼了 滿屏的代碼看的不舒服。
好了,大家有興趣去試試吧。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容