页面跳转过度动画使用

GitHub地址:https://github.com/huzenan/EasyTransition

使用方法

1.依赖注入

compile 'com.github.huzenan:EasyTransition:v1.0.0'

2.在跳转界面的时候使用该代码跳转

//后面的参数必须要与跳转的界面ID有相同的,因为配对到两个相同的ID,该框架就会自己做过渡动画
 EasyTransitionOptions options=EasyTransitionOptions.makeTransitionOptions(getActivity(),
                    view.findViewById(R.id.house_details_img_banner),
                    view.findViewById(R.id.item_owner_house_txt_title)
            );
            EasyTransition .startActivity(new Intent(getContext(),HouseDetailsActivity.class),options);

3.在跳转之后的界面使用该代码

private fun initOtherViews() {
        layout_gone_content.visibility = View.VISIBLE
        layout_gone_content.alpha = 0f
        layout_gone_content.translationY = -30f
        layout_gone_content.animate()
                .setDuration(300)
                .alpha(1f)
                .translationY(0f)

        layout_gone_buttom.visibility = View.VISIBLE
        layout_gone_buttom.alpha = 0f
        layout_gone_buttom.translationY = -30f
        layout_gone_buttom.animate()
                .setDuration(300)
                .alpha(1f)
                .translationY(0f)
    }

    private fun dismissActivity(){
        layout_gone_content.animate()
                .setDuration(300)
                .alpha(0f)
                .translationY(-30f)
        layout_gone_buttom.animate()
                .setDuration(300)
                .alpha(0f)
                .translationY(-30f)
                .setListener(object :AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator?) {
                        //回到之前的界面,第二个参数为动画执行时间
                        EasyTransition.exit(this@HouseDetailsActivity, 300, DecelerateInterpolator())
                    }
                });
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_house_details)
        //第二个参数为时间,第四个参数为跳转完毕的监听
        EasyTransition.enter(this,300,DecelerateInterpolator(),object: AnimatorListenerAdapter() {
            override fun onAnimationEnd(animation: Animator?) {
                initOtherViews()
            }
        })
    }

  override fun onBackPressed() {
        //super.onBackPressed()
       dismissActivity()
    }

你可能感兴趣的:(页面跳转过度动画使用)