Xamarin.android Activity動畫轉場效果實現

來源:互聯網
上載者:User

標籤:樣式   sla   post   效果   over   theme   新增內容   ide   div   

http://blog.csdn.net/esunshine1985/article/details/44302903

 

1.在Resources——values下建立styles.xml,新增內容如下:

[html] view plain copy
  1. <resources xmlns:android="http://schemas.android.com/apk/res/android">  
  2.     <style name="AppTheme" parent="@android:style/Theme">       
  3.         <item name="android:windowNoTitle">true</item> <!-- 設定沒有標題 -->  
  4.         <item name="android:textSize">20sp</item>   <!-- 設定文字大小 -->  
  5.           <item name="android:textColor">#F34141</item>  
  6.         <item name="android:background">@android:color/background_light</item>  
  7.         <!-- 設定activity切換動畫 -->  
  8.         <item name="android:windowAnimationStyle">@style/activityAnimation</item>  
  9.     </style>  
  10.     <!-- animation 樣式 -->  
  11.     <style name="activityAnimation" parent="@android:style/Animation">  
  12.         <item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item>  
  13.       <item name="android:activityCloseExitAnimation">@anim/slide_right_out</item>  
  14.         <item name="android:activityOpenExitAnimation">@anim/slide_left_out</item>  
  15.         <item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item>  
  16.     </style>  
  17. </resources>  

2.在Resources下建立檔案夾anim,在這個建立的檔案夾下面建立四個檔案,分別是

(1)slide_left_in.xml

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.   <translate android:duration="300" android:fromXDelta="-100.0%p" android:toXDelta="0.0" />  
  5. </set>  

(2)slide_left_out.xml

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.   <translate android:duration="300" android:fromXDelta="0.0" android:toXDelta="-100.0%p" />  
  5. </set>  

(3)slide_right_in.xml

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.   <translate android:duration="300" android:fromXDelta="100.0%p" android:toXDelta="0.0" />  
  5. </set>  

(4)slide_right_out.xml

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.   <translate android:duration="300" android:fromXDelta="0.0" android:toXDelta="100.0%p" />  
  5. </set>  

3.修改AndroidManifest.xml檔案(紅色標註的部分)

<application android:theme="@style/AppTheme"></application>
4.在MainActivity.cs中的切換按鈕的代碼:

[html] view plain copy
  1. button.Click += delegate  
  2. {  
  3.     Intent intent = new Intent();  
  4.     intent.SetClass(this, typeof(Activity2));  
  5.     StartActivity(intent);  
  6.     OverridePendingTransition(Resource.Animation.slide_left_in, Resource.Animation.slide_right_out);  
  7. };  

 

Xamarin.android Activity動畫轉場效果實現

相關文章

聯繫我們

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