我不确定这是否是一个缺陷,或者我在这里做错了什么。当我将ImageView作为两个活动之间的共享元素时,如果结束图像视图具有填充,则图像视图不再尊重屏幕底部的导航栏。如果我将填充移动到容器视图中,或者切换到使用边距,则可以正常工作。
第二张imageView上带填充的动画视频:https://www.youtube.com/watch?v=hg4bc6h2u5o&feature=youtu.be
第二张imageView上没有填充的动画视频:https://www.youtube.com/watch?v=pW4hyAfn9Hs&feature=youtu.be
第一个活动xml:
<LinearLayout
android:id="@+id/title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/header_elevation"
android:orientation="vertical"
android:transitionGroup="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/header_elevation"
android:background="?attr/colorPrimary" />
...
<!-- other header layouts -->
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/header_title_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/title_container"
android:layout_alignTop="@+id/title_container"
android:background="?android:colorAccent"
android:elevation="@dimen/header_elevation"
android:visibility="invisible" />
<ImageView
android:id="@+id/comic_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:contentDescription="@string/placeholder_image_description"
android:src="@drawable/dog_eat_cat"
/>
第二个活动xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:paddingTop="80dp"
/>
</RelativeLayout>
第一项活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Slide ts = new Slide(Gravity.TOP);
ts.excludeTarget(android.R.id.statusBarBackground, true)
.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setReenterTransition(ts);
getWindow().setExitTransition(ts);
... // set up views
}
public void openActivity() {
imageView.setTransitionName(PagesActivity.SHARED_IMAGE_NAME);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
image, PagesActivity.SHARED_IMAGE_NAME);
startActivity(intent, options.toBundle());
}
第二项活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getEnterTransition().excludeTarget(android.R.id.statusBarBackground, true)
.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().getReturnTransition().excludeTarget(android.R.id.statusBarBackground, true)
.excludeTarget(android.R.id.navigationBarBackground, true);
... //Load views
imageView.setTransitionName(SHARED_IMAGE_NAME);
}