日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 电视关闭动画,Activity 展开和关闭动画

發布時間:2024/9/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 电视关闭动画,Activity 展开和关闭动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

平常從一個 Activity A打開另個一個Activity B ,一般 Activity B 都是從屏幕右邊出來。而關閉 Activity B 返回Activity A ,則 Activity B 會從左邊沿向右邊沿消失。有時候,想讓新的 Activity 從屏幕的底部彈出,或者屏幕的中間向彈出,或者想讓Activity從屏幕的中間收回。本文章講的是這中需要效果。

實現原理

主要是 Activity 類的 overridePendingTransition(int enterAnim, int exitAnim) 方法的調用,在 res/anim目錄下創建所需的動畫文件,然后在 overridePendingTransition(int enterAnim, int exitAnim) 方法中調用動畫即可。

效果圖

show_activity_anim

具體代碼

在 res/anim 目錄下新建你需要的動畫文件,例如,我需要新的 Activity 從頂部向上彈出,然后從頂部向底部收回。那么我創建了activity_open_from_bottom_to_top.xml 文件,activity_close_from_top_to_bottom.xml 文件和 activity_keep_status.xml 文件。如下

activity_open_from_bottom_to_top.xml

android:duration="1500"

android:fromYDelta="100%p"

android:toYDelta="0"/>

android:fromAlpha="0.2"

android:toAlpha="1.0"

android:duration ="1500"/>

activity_close_from_top_to_bottom.xml

android:duration="1500"

android:fromYDelta="25"

android:toYDelta="100%p"/>

android:fromAlpha="1.0"

android:toAlpha="0.2"

android:duration ="1500"/>

activity_keep_status.xml

android:duration="1500"

android:fromYDelta="0"

android:toYDelta="10%p"/>

android:fromAlpha="1.0"

android:toAlpha="0.8"

android:duration ="1500"/>

然后在Activity的代碼中,用 overridePendingTransition(int enterAnim, int exitAnim) 方法調用這三個文件。

在啟動 Activity 的地方:

public static void startMe(Activity activity, String title, ArrayList imageList, int position) {

Intent intent = new Intent(activity, PhotoViewGroupActivity.class);

intent.putExtra(TAG_IMAGE_LIST, imageList);

intent.putExtra(TAG_POSITION, position);

intent.putExtra(TAG_TITLE, title);

activity.startActivity(intent);

activity.overridePendingTransition(R.anim.activity_photo_center_to_edge, R.anim.activity_photo_keep_status);

}

在退出 Activity 的地方:

@Override

public void finish() {

super.finish();

overridePendingTransition(0, R.anim.activity_photo_edge_to_center);

}

關于overridePendingTransition(enterAnim,exitAnim)方法

關于此方法,我們可以點進去看一下源碼的注釋怎么說。

/**

* Call immediately after one of the flavors of {@link #startActivity(Intent)}

* or {@link #finish} to specify an explicit transition animation to

* perform next.

*

*

As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative

* to using this with starting activities is to supply the desired animation

* information through a {@link ActivityOptions} bundle to

* {@link #startActivity(Intent, Bundle)} or a related function. This allows

* you to specify a custom animation even when starting an activity from

* outside the context of the current top activity.

*

* @param enterAnim A resource ID of the animation resource to use for

* the incoming activity. Use 0 for no animation.

* @param exitAnim A resource ID of the animation resource to use for

* the outgoing activity. Use 0 for no animation.

*/

public void overridePendingTransition(int enterAnim, int exitAnim) {

try {

ActivityManager.getService().overridePendingTransition(

mToken, getPackageName(), enterAnim, exitAnim);

} catch (RemoteException e) {

}

}

根據此處的說明,第一個參數 enterAnim 是指即將要到來的 Activity 的動畫資源文件,第二個參數exitAnim是即將要離開 Activity 的動畫資源文件。兩個參數都可以傳入0作為無動畫。

關于

總結

以上是生活随笔為你收集整理的android 电视关闭动画,Activity 展开和关闭动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。