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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 图片查看动画,Android 共享动画实现点击列表图片跳转查看大图页面

發(fā)布時間:2025/3/19 Android 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 图片查看动画,Android 共享动画实现点击列表图片跳转查看大图页面 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

主要內(nèi)容使用系統(tǒng)提供的 API 實現(xiàn)共享動畫

在實現(xiàn)過程中遇到的問題圖片點擊和關(guān)閉之后會出現(xiàn)短暫的黑屏問題實現(xiàn)的動畫效果如下:

共享動畫.gif

具體實現(xiàn)這個效果是在兩個頁面之間的切換動畫,既然是兩個頁面之間的切換,那么我們頁面跳轉(zhuǎn)代碼,設(shè)置跳轉(zhuǎn)動畫,即可。

頁面跳轉(zhuǎn)的代碼如下:Intent?intent?=?new?Intent(context,?BigImageActivity.class);

intent.putExtra(AppConfig.IMAGE_URL,imageUrl);//?添加跳轉(zhuǎn)動畫context.startActivity(intent,

ActivityOptionsCompat.makeSceneTransitionAnimation(

(Activity)?context,

shareImage,

context.getString(R.string.share_pic_str))

.toBundle());

可以看到這里用到了ActivityOptionsCompat.makeSceneTransitionAnimation,這個就是頁面跳轉(zhuǎn)的轉(zhuǎn)場動畫。

通過查看源碼可以知道這個轉(zhuǎn)場動畫只支持 Android 5.0以上, 它的源碼實現(xiàn)如下:public?static?ActivityOptionsCompat?makeSceneTransitionAnimation(Activity?activity,

View?sharedElement,?String?sharedElementName)?{????????if?(Build.VERSION.SDK_INT?>=?21)?{????????????return?createImpl(ActivityOptions.makeSceneTransitionAnimation(

activity,?sharedElement,?sharedElementName));

}????????return?new?ActivityOptionsCompat();

}????//?上面的?makeSceneTransitionAnimation?方法的實現(xiàn)

public?static?ActivityOptions?makeSceneTransitionAnimation(Activity?activity,?View?sharedElement,?String?sharedElementName)?{????????throw?new?RuntimeException("Stub!");

}????//?上面的?makeSceneTransitionAnimation?方法的另一個實現(xiàn)?,可以看出是共享動畫是支持多個視圖的

@SafeVarargs

public?static?ActivityOptions?makeSceneTransitionAnimation(Activity?activity,?Pair...?sharedElements)?{????????throw?new?RuntimeException("Stub!");

}第一個參數(shù):上下文

第二個參數(shù):轉(zhuǎn)場動畫作用的 View 控件

第三個參數(shù):共享字符串,在xml頁面布局中定義

第二個參數(shù)這里是ImageView控件,第三個參數(shù)是自己定義的字符串,這里是share_image_view。

那么在布局代碼中的實現(xiàn)如下:<?xml ?version="1.0"?encoding="utf-8"?>

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/iv_grid_welfare"

android:layout_width="match_parent"

android:layout_height="250dp"

android:scaleType="centerCrop"

android:transitionName="@string/share_str"/>

大圖頁面布局如下:<?xml ?version="1.0"?encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".big_image.BigImageActivity">

android:id="@+id/iv_big_image"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:scaleType="centerCrop"

android:transitionName="@string/share_str"/>

從下一個頁面返回關(guān)閉共享動畫

使用 finishAfterTransition(); 替換 finish() 關(guān)閉頁面。

以上就實現(xiàn)了兩個頁面之間跳轉(zhuǎn)的共享動畫效果。

但是動畫從大圖頁面返回時會出現(xiàn)黑屏或者白屏。這是什么原因呢?

這個原因是由于由于我們Activity設(shè)置的主題決定的,在 AndroidManifest.xml中找到我們設(shè)置的主題,修改為透明主題即可,Theme代碼如下:

android:name=".big_image.BigImageActivity"

android:theme="@style/BigImageTranslateTheme"?/>

true

true

@android:color/transparent

作者:_龍衣

鏈接:https://www.jianshu.com/p/c564f099cd4e

總結(jié)

以上是生活随笔為你收集整理的android 图片查看动画,Android 共享动画实现点击列表图片跳转查看大图页面的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。