在.smoothScrollToPosition()完​​成滚动后执行动画

时间:2017-09-09 15:08:53

标签: android material-design android-animation android-5.0-lollipop

我正在使用网格RecyclerView,如果用户点击半可见项目,RecyclerView滚动到该位置,然后触发意图以使用SharedElementTransition打开新活动

问题在于两者

mRecyclerView.smoothScrollToPosition(adapterPosition);

getActivity().startActivity(myIntent, options.toBundle());

同时执行,因此滚动动画在SharedElementTransition的同时发生,这是一团糟。 我想仅在滚动动画完成且recyclelerview处于静止状态时启动intent。我的代码:

@Override
    public void onClick(View view) {
        int adapterPosition = WallHolder.this.getAdapterPosition();
        Wallpaper w = mWallAdapter.getList().get(adapterPosition);
        mRecyclerView.smoothScrollToPosition(adapterPosition);

        if(getActivity() != null){
            Gson gson = new Gson();
            String serialized = gson.toJson(w);
            Intent myIntent = new Intent(getActivity(), DetailActivity.class);
            myIntent.putExtra("serialized", serialized);

            myIntent.putExtra("trans_name", ViewCompat.getTransitionName(mImageView));
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                    getActivity(),
                    mImageView,
                    ViewCompat.getTransitionName(mImageView));
            getActivity().startActivity(myIntent, options.toBundle());}}

0 个答案:

没有答案