切換兩個activity,切換activity
下面是一個切換兩個activity是過度動畫效果執行個體:
(注意裡面的overridePendingTransition()方法)
Java代碼
1. @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);
}
1.若要實現淡入淡出效果,就要將overridePendingTransition()方法修改為:overridePendingTransition(Android.R.anim.fade_in,android.R.anim
.fade_out);
2.若要實現左向右滑入的效果 :
overridePendingTransition(Android.R.anim.slide_in_left,android.
R.anim.slide_out_right);
3.實現zoomin 和zoomout,即類似iphone的進入和退出時的效果:
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
這裡我們自己定義zoomin.xml和zoomout.xml
zoomin.xml 代碼:
1. <?xml version="1.0" encoding="utf-8"?>
2. <set
3. xmlns:Android="http://schemas.android.com/apk/res/android"
4. Android:interpolator="@android:anim/decelerate_interpolator">
<scale Android:fromXScale="2.0" android:toXScale="1.0"
5. Android:fromYScale="2.0" android:toYScale="1.0"
6. Android:pivotX="50%p" android:pivotY="50%p"
7. Android:duration="@android:integer/config_mediumAnimTime" />
</set>
可能有很多人不理解其中的android:interpolator="@android:anim/decelerate_interpolator"是什麼含義,文檔裡說的也不太清楚,其實很簡單,看下面:
interpolator定義一個動畫的變動率(the rate of change)。這使得基本的動畫效果(alpha, scale, translate, rotate)得以加速,減速,重複等。
用通俗的一點的話理解就是:動畫的進度使用 Interpolator 控制。Interpolator 定義了動畫的變化速度,可以實現勻速、正加速、負加速、無規則變加速等。Interpolator 是基類,封裝了所有 Interpolator 的共同方法,它只有一個方法,即 getInterpolation (float input),該方法 maps a point on the timeline to a multiplier to be applied to the transformations of an animation。Android 提供了幾個 Interpolator 子類,實現了不同的速度曲線,如下:
AccelerateDecelerateInterpolator 在動畫開始與介紹的地方速率改變比較慢,在中間的時侯加速
AccelerateInterpolator 在動畫開始的地方速率改變比較慢,然後開始加速
CycleInterpolator 動畫迴圈播放特定的次數,速率改變沿著正弦曲線
DecelerateInterpolator 在動畫開始的地方速率改變比較慢,然後開始減速
LinearInterpolator 在動畫的以均勻的速率改變
對於 LinearInterpolator ,變動率是個常數,即 f (x) = x.
public float getInterpolation(float input) {
return input;
}
Interpolator其他的幾個子類,也都是按照特定的演算法,實現了對變動率。還可以定義自己的 Interpolator 子類,實現拋物線、自由落體等物理效果。
就到這裡了,希望對大家有協助...
android 兩個activity之間切換會有飛入的效果,問怎去掉這個效果
兩個activity切換之間的動畫是可以自訂的,只需要在activity中加上overridePendingTransition(enterAnim, exitAnim)就OK了,enterAnim是當前activity加入的動畫,exitAnim是出的。頁面的飛入效果是不能去掉的,這是系統預設的,如果你想實現沒有動畫的效果,只能用另外的在一個全域布局中用addView和removeView來實現了。
android怎在2個activity間切換
Intent intent = new Intent();
intent.setClass(A.this,B.class);
startActivity(intent);