我正在对Android L中的共享元素转换进行一些基本的探索.我设置的简单示例在活动转换期间有一个从屏幕顶部转换到屏幕底部的图像视图,并且我已经延长了转换持续时间所以我可以看到工作正常.到目前为止,我遇到了两个问题,试图了解共享元素转换的工作原理.
1)仅使用Enter/Return转换(Exit/Reenter设置为null).输入转换很好,但是当按下后退按钮时,视图会动画一段时间,停止,然后重新出现在最终位置.似乎与此问题类似,但我已将所有Exist/Reenter过渡设置为null,因此不确定为什么会发生这种情况.
2)仅使用退出/重新转换时(Enter/Return设置为null).没有任何事情发生,视图在屏幕上向下转换,如下面的默认输入转换(300毫秒持续时间),当按下后退时,视图弹回到其原始位置.
如何使用退出/重新转换?
这是我的代码:
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/ic_launcher"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate!"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
activity_second.xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/ic_launcher"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
getWindow().setAllowEnterTransitionOverlap(false);
getWindow().setAllowReturnTransitionOverlap(false);
getWindow().setSharedElementExitTransition(exitTransition());
getWindow().setSharedElementReenterTransition(reenterTransition());
//getWindow().setSharedElementExitTransition(null);
//getWindow().setSharedElementReenterTransition(null);
setContentView(R.layout.activity_main);
final View iView = findViewById(R.id.imageView);
iView.setTransitionName("image");
final Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new …Run Code Online (Sandbox Code Playgroud) android android-5.0-lollipop activity-transition shared-element-transition