共享单元转换视图之间(不活动或片段) [英] Shared Element Transitions Between Views (not Activities or Fragments)

查看:172
本文介绍了共享单元转换视图之间(不活动或片段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我使用的是基于视图的方法来开发一个Android应用程序,如例如在下面的文章中描述:<一href="http://corner.squareup.com/2014/10/advocating-against-android-fragments.html">http://corner.squareup.com/2014/10/advocating-against-android-fragments.html

Let's say I'm using a view-based approach to develop an Android application like for example described in the following article: http://corner.squareup.com/2014/10/advocating-against-android-fragments.html

所以现在我有两个全屏幕视图。一个是可见的,并包含图像的网格。另一种是隐藏的,并且是要被点击图像的细节视图。如果没有在点击网格中的图像转换网格视图将被隐藏,详细视图将显示。现在,如果我想有一个类似于网格视图中的小图像和详细视图中放大图像之间的共享元素的过渡什么。是这样的可能吗?

So now I have two full screen views. One is visible and contains a grid of images. The other is hidden and is a detail view of the to-be-clicked image. Without transitions on clicking an image in the grid the grid view will be hidden and the detail view will be shown. Now what if I want to have something akin to a shared element transition between the small image in the grid view and the larger image in the detail view. Is something like this possible?

图像

推荐答案

是的,过渡允许这一点。

Yes, transitions allow this.

在你的榜样,你有两个网格,已经详细视图层次结构。要使用的过渡,这将更好地工作,如果详细视图不会在视图层次开始。您需要交换两种观点。

In your example, you have both the grid and detail views already in your hierarchy. To use transitions, it will work better if the detail view does not start in the View hierarchy. You need to exchange the two views.

有两种(类似)的方式来做到这一点。首先是在一个场景中的网格视图。然后使用TransitionManager.go(detailScene,过渡)。

There are two (similar) ways to do it. The first is to have the grid view in a scene. Then use TransitionManager.go(detailScene, transition).

的第二种方法是使用TransitionManager.beginDelayedTransition然后交换的详细布局为网格布局

The second way is to use TransitionManager.beginDelayedTransition and then swap the detailed layout for the grid layout.

有共同的观点有共同之处是很重要的。通常,它是一个视图ID或transitionName。这个链接会告诉过渡系统,即使意见不同的实例。

It is important to have the shared views have something in common. Typically it is a View ID or transitionName. This linking will tell the transition system that even though the views are different instances.

这是你想要使用的过渡是@android:过渡/移动。它结合了ChangBounds,ChangeTransform,ChangeImageTransform和ChangeClipBounds。你必须在共享的元素意见的目标这一点。它看起来像您需要的进入和/或退出的看法另一过渡(淡出?)。

The transition that you'll want to use is @android:transition/move. It combines ChangBounds, ChangeTransform, ChangeImageTransform, and ChangeClipBounds. You'll have to target this at the shared element views. It looks like you will need another transition (Fade?) for the entering and /or exiting views.

事情是这样的:

TransitionSet shared = ...
shared.addTarget("sharedName");
gridElement.setTransitionName("sharedName");
Fade fade = new Fade();
fade.excludeTarget("sharedName", true);
TransitionSet set = new TransitionSet();
set.addTransition(shared)
   .addTransition(fade);
TransitionManager.go(detailScene, set);

这篇关于共享单元转换视图之间(不活动或片段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆