我有全局应用程序中的订阅源数据列表。 我MainAcitivty
结束活动中的自定义共享元素转换
// selected item event
Intent intent = new Intent(this, DetailActivity.class);
intent.putExtra("item_feed_index", selectedItemIndex);
FeedViewHolder viewHolder = getViewHolderFromPosition(position);
Pair<View, String> pair1 = Pair.create(viewHolder.imageView, "TransitionName.Feed.Image");
Pair<View, String> pair2 = Pair.create(viewHolder.textView, "TransitionName.Feed.Text");
Pair<View, String> pair3 = Pair.create(viewHolder.button, "TransitionName.Feed.Button");
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, pair1, pair2, pair3);
startActivity(intent, options.toBundle());
用这个代码,以使过渡从我RecyclerView
它的工作。但问题是,在DetailActivity
,我有另一个垂直列表,用户可以向下/向上滚动以更改列表中的Feed项目(这也改变了滚动索引)。
当从DetailActivity
后退时,我希望退出动画转换在正确的查看Feed索引上执行。我怎样才能做到这一点?
这是MainActivity
中的代码onActivityResult
,它将回收卷动到正确的位置,但退出过渡动画不正确的位置。
int currentFeedIndex = Application.getInstance().getCurrentViewingFeed();
if (currentFeedIndex > 0 && currentFeedIndex < adapter.getItemCount()) {
if (gridLayoutManager != null) {
gridLayoutManager.scrollToPositionWithOffset(currentFeedIndex + 1, 0);
}
}
我在寻找退出运行动画之前改变对列表的方式
更新:这里是DetailActivity,在这里我给你转型名意见的布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="TransitionName.Feed.Image" />
<TextView
android:id="@+id/tvLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:transitionName="TransitionName.Feed.Text"/>
<Button
android:transitionName="TransitionName.Feed.Button"
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_below="@+id/tvLogo"/>
</RelativeLayout>
你可以发布你是怎么分配的过渡代码名称到'DetailActivity'的视图? – rom4ek
@ rom4ek我更新了代码 – R4j