我正在使用网格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());}}