Delay shared element transition to complete statelist animation

亡梦爱人 提交于 2019-12-02 08:38:58

问题


I've been trying out shared element transition on Lollipop. i have a recyclerview which loads some cards and one click the card expands to its details in the next activity.

I have set a ripple effect and a StateListAnimator on the card. But those are not visible cause the transition starts before these effects are completed.

Is there any way to delay the transition so that it can wait for the statelist animator and ripple to complete?

Here is the code I use

ActivityOptions options = null;
        if (Utilities.isLollipop()) {
            options = ActivityOptions.makeSceneTransitionAnimation(this, Pair.create(view, "hero_view"), Pair.create((View) fab, "fab"));
 startActivity(detailIntent, options.toBundle());
        }

Thanks in advance


回答1:


I ended up using a work around, but I still would want to know what is the right way of doing this and therefore leaving the question open.

The work around I did was 1. remove the state list animator and add that as an animator in the onclick method. 2. Used a Handler to post a delayed call to the activity

new Handler().postDelayed(new Runnable() {
                      @Override
                      public void run() {

                          Intent i=new Intent(SearxhJobs.this,JobsTypes.class);
                          startActivity(i);
                      }
                  }, 200);

P.S- I did end up removing the effect as it was not very intuitive.




回答2:


The way that may help some that already have the Transitions setup in Second Activity:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().getSharedElementEnterTransition().setDuration(500);
    getWindow().getSharedElementReturnTransition().setDuration(500)
        .setInterpolator(new DecelerateInterpolator());
}


来源:https://stackoverflow.com/questions/29224653/delay-shared-element-transition-to-complete-statelist-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!