Android:改變Activity切換方式

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   os   io   strong   

overridePendingTransition(enterAnim, exitAnim);

Intent intent =new Intent(this,item2.class);startActivity(intent);this.finish();overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); 

要整個應用改切換方式的話,那就用style控制吧

1、在res檔案夾建立anim檔案夾

2、添加以下檔案:

slide_left_in.xml  從左邊進來

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="200"        android:fromXDelta="-100.0%p"        android:toXDelta="0.0" /></set>

slide_left_out.xml 從左邊出去

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="200"        android:fromXDelta="0.0"        android:toXDelta="-100.0%p" /></set>

slide_right_in.xml 從右邊進來

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="200"        android:fromXDelta="100.0%p"        android:toXDelta="0.0" /></set>

slide_right_out.xml  從右邊出去

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="200"        android:fromXDelta="0.0"        android:toXDelta="100.0%p" /></set>

屬性講解:

translate 位置轉移動畫效果

android:fromXDelta="0" -----------從0座標開始開始
android:toXDelta="-100%p" ------移動距離到父層的-100%

兩個參數都是指控制項相對於parent的位移距離

android:duration="200" -----------期間

 

3、修改主題樣式

    <!-- Application theme. -->    <style name="AppTheme" parent="AppBaseTheme">        <!-- All customizations that are NOT specific to a particular API-level can go here. -->        <item name="android:windowAnimationStyle">@style/activityAnimation</item>    </style>        <style name="activityAnimation" parent="@android:style/Animation">          <item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item>          <item name="android:activityOpenExitAnimation">@anim/slide_left_out</item>          <item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item>          <item name="android:activityCloseExitAnimation">@anim/slide_right_out</item>      </style>  

 

執行個體下載>>>>>>>>>>>>>

 

聯繫我們

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