The Road to Moving Bricks - Transition Animation ActivityOptions

Contact scene:
write picture description here

required in the development documentation.

Requirements: Click the item picture in the list, zoom in and jump to the big picture interface, when the big picture interface is closed, zoom out and return to the item picture in the list

Implementation: use ActivityOptions.makeSceneTransitionAnimation

Process:
1. Add in the theme of jumping out of activity in the manifest file

 <item name="android:windowAllowEnterTransitionOverlap">true</item>

Because the transition animation is only available after 5.0, it is necessary to create a new values-21 package under the res file, and create a new styles file in it, copy the general style, fill in the above, and complete

2. Add a jump method at the click jump

public static void toNextActivity(Activity mActivity, Intent mIntent,View mView,String tag){
        // 判断版本号,转场动画是在5.0以后添加的,所以它只在21版本以上起作用
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            //设置转场动画,makeSceneTransitionAnimation为固定动画,实现放大效果,
            // 参数依次为:mActivity=当前activity,mView=当前跳出view,tag=与下一个activity联系的string串
            //tag的使用,与下一个界面产生联系
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation( mActivity, mView, tag);
            mActivity.startActivity(mIntent, options.toBundle());
        } else {
            NextActivityUtil.toNextActivity( mActivity, mIntent, false);

        }
    }

Jump out to complete.

3. Jump into section


    <ImageView
        android:id="@+id/iv2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:transitionName="pic"
        android:src="@mipmap/aa" />

android:transitionName=”pic” The pic in it must be the same as the tag value that jumped out in 2, and the two values ​​must be the same

4. Jump into the interface to close and return

public static void finishAfterTransition1(Activity mActivity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mActivity.finishAfterTransition();
        } else {
            NextActivityUtil.finishActivity(mActivity);
        }

    }

fully completed! There are other effects, I have time to organize

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324885323&siteId=291194637