Android動畫實踐結論

來源:互聯網
上載者:User

標籤:android動畫   平移動畫   

實踐出真知:

一>平移動畫

overridePendingTransition(R.anim.enterAnim,R.anim.exitAnim);

方法中第一個參數表示進enterAnim,第二個參數表示出exitAnim;怎麼理解呢?

比如:如果我寫出這樣的一個效果,如同在網易新聞上的一樣。當你點擊一條新聞的時候,好像當前頁面不動,然後所請求的新聞頁面從右向左逐漸平移過來並完全遮掩(覆蓋)當前頁面。如果實現它,看XML代碼:

/**  enterAnim  */
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator" >    <translate        android:duration="500"        android:fromXDelta="100%"        android:toXDelta="0%"         android:interpolator="@android:anim/accelerate_interpolator"/></set>
/** exitAnim  */
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator" >    <translate        android:duration="500"        android:fromXDelta="0%"        android:interpolator="@android:anim/decelerate_interpolator"        android:toXDelta="0%" /></set>

然後,當你要跳轉到另一頁面時候在startActivity(Intent intent);之後放置上面的方法。
運行一下效果你就會知道,所謂的“進”就等同於,當前不想要看到的頁面。咱要讓它消失;相反,則”出“就是讓你想要看到的新頁面呈現出來並遮住(覆蓋)當前頁;

當點擊返回時候,應用效果和上面的點擊效果相反;效果:當前頁向右平移撤去,原先當前頁下面的頁面原封的呈現出來。

當然還是使用上面的方法,此時XML代碼如下;

/** enterAnim  */
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator" >                <translate        android:duration="500"        android:fromXDelta="0%"        android:interpolator="@android:anim/accelerate_interpolator"        android:toXDelta="0%" /> </set>
/** exitAnim  */
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator" >                <translate        android:duration="500"        android:fromXDelta="0%"        android:interpolator="@android:anim/decelerate_interpolator"        android:toXDelta="100%" /></set>

依然使用方法:

overridePendingTransition(R.anim.enterAnim,R.anim.exitAnim);


思路與請求效果思路相反;

其實,平移就是相當於一條河流;首先要知道該河流要想那個方向走。

比如向左:設定定方法的第一個參數(令當前頁面向左平移)是從右向左移動,緊跟著請求頁面(第二個參數)也是同方向從右向左平移。這樣才能實現平移的流動性;

 

待續。。。。





 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.