将凌空的NetworkImageView转换为另一个活动不会显示

时间:2016-09-25 01:49:32

标签: java android listview android-activity transition

我正在开发一个简单的应用程序,其中包含一个带有NetworkImageView的ListView。当用户点击ListView中的一行时,我想将NetworkImageView转换为其他活动。

我按照这个来源:https://guides.codepath.com/android/Shared-Element-Activity-Transition

问题是我转换到的活动中缺少NetworkImageView。任何人都可以指出我正确的方向,因为我不知道我错过了什么。

第1步:启用窗口内容转换

style.xml

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
    <!-- enable window content transitions -->
    <item name="android:windowActivityTransitions">true</item>

    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

第2步:分配通用转换名称

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"
tools:context=".MainActivity" >

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp"/>
</RelativeLayout>

list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp" >

<!-- Thumbnail Image -->
<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/thumbnail"
    android:transitionName="thumbnail"
    android:layout_width="100dp"
    android:layout_height="67dp"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="8dp" />

<!-- Movie Title -->
<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/thumbnail"
    android:layout_toRightOf="@+id/thumbnail"
    android:textSize="@dimen/title"
    android:textStyle="bold"
    android:ellipsize="end"
    android:singleLine="true"/>

<!-- Genre -->
<TextView
    android:id="@+id/genre"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:layout_marginTop="5dp"
    android:layout_toRightOf="@+id/thumbnail"
    android:textColor="@color/genre"
    android:textSize="@dimen/genre" />
</RelativeLayout>

activity_detail_event.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">

<!-- Thumbnail Image -->
<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/cover"
    android:transitionName="thumbnail"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

第3步:开始活动

MainActivity.java

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        final View thumbnail = view.findViewById(R.id.thumbnail);
        Intent intent = new Intent(MainActivity.this, DetailEventActivity.class);

        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, thumbnail, "thumbnail");
            startActivity(intent, options.toBundle());
    }
});

0 个答案:

没有答案