類比優酷像關電視一樣的退出效果

來源:互聯網
上載者:User

其實所謂像關電視一樣的退出效果就是一個動畫而已,好吧,看到這裡的朋友可以先自己想想,其實思路是很簡單的。

1.要求螢幕瞬間白屏。

2.白色螢幕以勻加速或勻減速向中間擠壓,直至一條白線後消失不見,整個過程大概200毫秒。

3.露出黑漆漆一片的黑色背景。

首先,布局檔案的寫法。有很多種,最簡單的就是利用RelativeLayout或者FrameLayout為應用首介面的根布局,如果應用的背景色本身為黑色最好,就像優酷一樣。如果應用的背景色不為黑色,那麼在根布局裡寫一:

  1. <FrameLayout 
  2.       android:id="@+id/fl_off" 
  3.         android:layout_width="fill_parent" 
  4.         android:layout_height="fill_parent" 
  5.         android:visibility="gone" 
  6.          > 
  7.     <ImageView 
  8.         android:layout_width="fill_parent" 
  9.         android:layout_height="fill_parent" 
  10.         android:background="@color/text_black" /> 
  11.     <ImageView 
  12.           android:id="@+id/iv_off" 
  13.         android:layout_width="fill_parent" 
  14.         android:layout_height="fill_parent" 
  15.         android:background="@color/text_white"  
  16.          android:visibility="gone"/> 
  17. </FrameLayout> 

第一個ImageView為黑色的背景色,第二個為白色的背景色。

下面是動畫檔案的寫法 res/anim/tv_off.xml:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <set android:shareInterpolator="false" 
  3. android:zAdjustment="top" 
  4.   xmlns:android="http://schemas.android.com/apk/res/android">
  5. <span></span> 
  6. <scale android:interpolator="@android:anim/accelerate_interpolator" 
  7. android:duration="200" 
  8. android:pivotX="50.0%" 
  9. android:pivotY="50.0%" 
  10. android:fromXScale="1.0" 
  11. android:toXScale="1.0" 
  12. android:fromYScale="1.0" 
  13. android:toYScale="0.0030" /> 
  14.     <scale android:interpolator="@android:anim/accelerate_interpolator" 
  15. android:duration="200" 
  16. android:pivotX="50.0%" 
  17. android:pivotY="50.0%" 
  18. android:startOffset="200" 
  19. android:fromXScale="1.0" 
  20. android:toXScale="0.0" 
  21. android:fromYScale="1.0" 
  22. android:toYScale="0.3" /> 
  23.     <alpha android:interpolator="@interpolator/accelerate_quint" 
  24. android:duration="400" 
  25. android:fillAfter="true" 
  26. android:fromAlpha="1.0" 
  27. android:toAlpha="0.0" 
  28. android:fillEnabled="true" /> 
  29. </set> 

這個很簡單,大家copy就行了。

因為動畫引用到了加速器,下面是加速器檔案的寫法 res/interpolator/accelerate_quint.xml:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <accelerateInterpolator android:factor="2.5" 
  3.   xmlns:android="http://schemas.android.com/apk/res/android" /> 

這是一個勻加速的加速器,加速倍數為2.5。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.