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

Android實(shí)現(xiàn)Reveal圓形Activity轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的完整步驟

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

前言

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

一、效果


二、知識(shí)點(diǎn)

CircularReveal動(dòng)畫(huà)、透明主題、轉(zhuǎn)場(chǎng)動(dòng)畫(huà)(非必須)

三、方案

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

  • 確定要顯示的圓形動(dòng)畫(huà)中心起點(diǎn)位置
  • 通過(guò)Intent將起點(diǎn)位置從Activity A傳遞B
  • Activity B主題需要是透明的,同時(shí)先隱藏布局視圖
  • 在Activity A中啟動(dòng)Activity B,Activity A先不銷毀
  • Activity B啟動(dòng)之后開(kāi)始動(dòng)畫(huà),在動(dòng)畫(huà)啟動(dòng)時(shí)顯布局視圖
  • 銷毀Activity A,如果需要返回則不銷毀

四、實(shí)現(xiàn)

4.1 初始界面Activity A

在Activity A中需要定義好主題、布局以及啟動(dòng)Activity B的方法。因?yàn)楫?dāng)不需要執(zhí)行返回動(dòng)畫(huà)的時(shí)候,要把Activity A銷毀,這時(shí)候一定是在后臺(tái)銷毀的,所以要把主題相關(guān)設(shè)置為透明,不然會(huì)在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è)置,這一步比較簡(jiǎn)單,這里以啟動(dòng)界面為例,顯示一張鋪滿全屏的圖片,下面覆蓋一個(gè)進(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中啟動(dòng)Activity B代碼如下,使用轉(zhuǎn)場(chǎng)動(dòng)畫(huà)API執(zhí)行,當(dāng)然也可以使用ActivityCompat.startActivity(this, intent, null); overridePendingTransition(0, 0);這種方式。在這段代碼中,把Activity A中開(kāi)始執(zhí)行Reveal圓形動(dòng)畫(huà)的坐標(biāo)點(diǎn)傳遞給Activity B,因?yàn)閯?dòng)畫(huà)是在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 動(dòng)畫(huà)界面Activity B

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

主題設(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í)行動(dòng)畫(huà)的代碼,先把根據(jù)不設(shè)置為不可見(jiàn),然后在跟布局測(cè)量完畢之后開(kāi)始執(zhí)行動(dòng)畫(huà)。

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();
}
}

最后實(shí)現(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/

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

相關(guān)文章

最新評(píng)論

五常市| 冀州市| 锦屏县| 宜黄县| 通江县| 涞源县| 贺州市| 大同县| 赫章县| 平定县| 云林县| 邵武市| 海南省| 凤山市| 江北区| 临城县| 静安区| 景德镇市| 香港| 启东市| 海林市| 龙井市| 牡丹江市| 罗源县| 邹平县| 曲麻莱县| 屏边| 威信县| 江川县| 六枝特区| 灵川县| 察雅县| 丽水市| 伊宁市| 德阳市| 青州市| 梁平县| 循化| 雷州市| 射阳县| 子长县|