最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)Reveal圓形Activity轉(zhuǎn)場動畫的完整步驟

 更新時間:2018年11月05日 10:05:06   作者:WPJY  
這篇文章主要給大家介紹了關(guān)于Android Reveal圓形Activity轉(zhuǎn)場動畫的實現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

Activity的轉(zhuǎn)場動畫很早就有,但是太過于單調(diào),樣式也不好看,本文將給大家介紹了關(guān)于Android實現(xiàn)Reveal圓形Activity轉(zhuǎn)場動畫的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧

一、效果


二、知識點

CircularReveal動畫、透明主題、轉(zhuǎn)場動畫(非必須)

三、方案

假設(shè)有兩個Activity A和B。Reveal圓形Activity轉(zhuǎn)場動畫效果先從A到B,那么基本方案如下:

  • 確定要顯示的圓形動畫中心起點位置
  • 通過Intent將起點位置從Activity A傳遞B
  • Activity B主題需要是透明的,同時先隱藏布局視圖
  • 在Activity A中啟動Activity B,Activity A先不銷毀
  • Activity B啟動之后開始動畫,在動畫啟動時顯布局視圖
  • 銷毀Activity A,如果需要返回則不銷毀

四、實現(xiàn)

4.1 初始界面Activity A

在Activity A中需要定義好主題、布局以及啟動Activity B的方法。因為當(dāng)不需要執(zhí)行返回動畫的時候,要把Activity A銷毀,這時候一定是在后臺銷毀的,所以要把主題相關(guān)設(shè)置為透明,不然會在Activity B中顯示Activity A銷毀界面。

<style name="FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

然后是布局設(shè)置,這一步比較簡單,這里以啟動界面為例,顯示一張鋪滿全屏的圖片,下面覆蓋一個進(jìn)度條。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".SplashActivity">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/wallace" />

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="180dp" />

</FrameLayout>

在Activity A中啟動Activity B代碼如下,使用轉(zhuǎn)場動畫API執(zhí)行,當(dāng)然也可以使用ActivityCompat.startActivity(this, intent, null); overridePendingTransition(0, 0);這種方式。在這段代碼中,把Activity A中開始執(zhí)行Reveal圓形動畫的坐標(biāo)點傳遞給Activity B,因為動畫是在Activity B中執(zhí)行的。

public void presentActivity(View view) {
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, view, "transition");
int revealX = (int) (view.getX() + view.getWidth() / 2);
int revealY = (int) (view.getY() + view.getHeight() / 2);

Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_CIRCULAR_REVEAL_X, revealX);
intent.putExtra(MainActivity.EXTRA_CIRCULAR_REVEAL_Y, revealY);

ActivityCompat.startActivity(this, intent, options.toBundle());

//ActivityCompat.startActivity(this, intent, null); overridePendingTransition(0, 0);
}

4.2 動畫界面Activity B

在Activity B中同樣需要定義好主題、布局以及執(zhí)行動畫的方法。上面方案中也說到,Activity B需要是透明主題,而且布局文件不能為透明,隨便設(shè)置一個背景即可。因為動畫效果是從Activity A過度到Activity B,也就是啟動Activity B一切準(zhǔn)備就緒之后,顯示其布局。同時開始執(zhí)行ViewAnimationUtils.createCircularReveal動畫,createCircularReveal會把根布局慢慢展開。這樣就形成了上面的動畫效果。

主題設(shè)置如下:

<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

布局設(shè)置如下,注意根布局背景設(shè)置:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

最后就是執(zhí)行動畫的代碼,先把根據(jù)不設(shè)置為不可見,然后在跟布局測量完畢之后開始執(zhí)行動畫。

if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
intent.hasExtra(EXTRA_CIRCULAR_REVEAL_X) &&
intent.hasExtra(EXTRA_CIRCULAR_REVEAL_Y)) {
rootLayout.setVisibility(View.INVISIBLE);
revealX = intent.getIntExtra(EXTRA_CIRCULAR_REVEAL_X, 0);
revealY = intent.getIntExtra(EXTRA_CIRCULAR_REVEAL_Y, 0);
ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
revealActivity(revealX, revealY);
rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
} else {
rootLayout.setVisibility(View.VISIBLE);
}
protected void revealActivity(int x, int y) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float finalRadius = (float) (Math.max(rootLayout.getWidth(), rootLayout.getHeight()) * 1.1);
// create the animator for this view (the start radius is zero) 
Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, x, y, 0, finalRadius);
circularReveal.setDuration(400);
circularReveal.setInterpolator(new AccelerateInterpolator());
// make the view visible and start the animation 
rootLayout.setVisibility(View.VISIBLE);
circularReveal.start();
} else {
finish();
}
}

最后實現(xiàn)效果如下:


五、參考:

  • https://android.jlelse.eu/a-little-thing-that-matter-how-to-reveal-an-activity-with-circular-revelation-d94f9bfcae28
  • https://codesnipps.simolation.com/post/android/create-circular-reveal-animation-when-starting-activitys/

好了,以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論

德清县| 荔浦县| 措美县| 浦城县| 辽源市| 宿州市| 正宁县| 大姚县| 会昌县| 东宁县| 顺平县| 隆回县| 阿勒泰市| 萨嘎县| 砚山县| 漯河市| 龙江县| 荃湾区| 饶阳县| 云霄县| 盱眙县| 女性| 韩城市| 弋阳县| 湘潭市| 绩溪县| 沙河市| 德庆县| 建昌县| 贵定县| 南陵县| 丁青县| 灵寿县| 台山市| 乌海市| 松潘县| 乌鲁木齐县| 当雄县| 门头沟区| 社会| 繁峙县|