編輯:Android開發實例
本文以實例形式展示了Android實現Activity界面切換添加動畫特效的方法,對於Android程序設計人員來說有很好的參考借鑒價值。具體方法如下:
了解Android程序設計的人應該知道,在Android 2.0之後有了overridePendingTransition(),其中裡面兩個參數,一個是前一個activity的退出,另一個activity的進入。
現看看下面這段示例代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.SplashScreen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent mainIntent = new Intent(SplashScreen.this, AndroidNews.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
overridePendingTransition(R.anim.mainfadein,
R.anim.splashfadeout);
}
}, 3000);
}
上面的代碼只是閃屏的一部分。
getWindow().setWindowAnimations(int);
這可沒有上個好但是也可以 。
實現淡入淡出的效果:
overridePendingTransition(Android.R.anim.fade_in,android.R.anim.fade_out);
由左向右滑入的效果:
overridePendingTransition(Android.R.anim.slide_in_left,android.R.anim.slide_out_right);
實現zoomin和zoomout,即類似iphone的進入和退出時的效果:
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
新建zoomin.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
Android:interpolator="@android:anim/decelerate_interpolator">
<scale Android:fromXScale="2.0" android:toXScale="1.0"
Android:fromYScale="2.0" android:toYScale="1.0"
Android:pivotX="50%p" android:pivotY="50%p"
Android:duration="@android:integer/config_mediumAnimTime" />
</set>
新建zoomout.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
Android:interpolator="@android:anim/decelerate_interpolator"
Android:zAdjustment="top">
<scale Android:fromXScale="1.0" android:toXScale=".5"
Android:fromYScale="1.0" android:toYScale=".5"
Android:pivotX="50%p" android:pivotY="50%p"
Android:duration="@android:integer/config_mediumAnimTime" />
<alpha Android:fromAlpha="1.0" android:toAlpha="0"
Android:duration="@android:integer/config_mediumAnimTime"/>
</set>
相信本文所述示例對大家的Android程序設計有一定的借鑒價值。
Android MediaPlayer(多媒體播放)
Android提供了許多方法來控制播放的音頻/視頻文件和流。其中該方法是通過一類稱為MediaPlayer。Android是提供MediaPlayer類訪問內置的媒體播放
Android本地化
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我
模仿優酷Android客戶端圖片左右滑動(自動切換)效果
本例是用ViewPager去做的實現,支持自動滑動和手動滑動,不僅優酷網,實際上有很多商城和門戶網
Android 完全退出應用程序的解決方法
有一種需要,我們在菜單項中點擊退出應用程序,應用程序就退出,不需要回到MainActivity設計:有兩個應用界面MainActivity和BActivity,以