アプリで共有要素遷移を作成しようとしています。activity1 にリストビューがあり、リストの各要素に画像ビューがあります。この画像は、ユーザーがリスト内の項目をクリックすると、2 番目の activity2 にも表示されます。
問題は次のとおりです。
java.lang.IllegalArgumentException: Shared element name must not be null
at android.app.ActivityOptions.makeSceneTransitionAnimation(ActivityOptions.java:470)
at android.app.ActivityOptions.makeSceneTransitionAnimation(ActivityOptions.java:431)
at android.support.v4.app.ActivityOptionsCompat21.makeSceneTransitionAnimation(ActivityOptionsCompat21.java:31)
at android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAnimation(ActivityOptionsCompat.java:134)
at com.frisbeeeapp.frisbeee.main_fragment.Main_All_Annonces$6$2.onItemClick(Main_All_Annonces.java:417)
at android.widget.AdapterView.performItemClick(AdapterView.java:300)
at android.widget.AbsListView.performItemClick(AbsListView.java:1143)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)
at android.widget.AbsListView$3.run(AbsListView.java:3833)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
change_image_transform.xml :
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeImageTransform />
</transitionSet>
そして、activity1 のレイアウトで宣言された imageview の抜粋:
<ImageView
android:id="@+id/allannonces_image"
android:transitionName="transitionImg"
android:layout_width="fill_parent"
android:layout_height="270dp"
android:scaleType="centerCrop"
android:layout_below="@+id/allannonces_imageuser"
android:layout_marginTop="18dp"/>
そして、ここに activity1 内のコードがあります:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Annonce currentAnnonce = (Annonce) list.getAdapter().getItem(position);
String titre = currentAnnonce.getTitle();
String cat = currentAnnonce.getCategorie();
String desc = currentAnnonce.getDescription();
String etat = currentAnnonce.getEtat();
String img = currentAnnonce.getImage();
String prix = currentAnnonce.getPrix();
String villeObj = currentAnnonce.getVilleObjet();
String codePostal = currentAnnonce.getCode_postal();
String departement = currentAnnonce.getDepartement();
String avatarUser = currentAnnonce.getImageUser();
String pseudoUser = currentAnnonce.getPseudoUser();
String dateDebut = currentAnnonce.getDate_debut();
String idAnnonce = currentAnnonce.getId();
String emailUser = currentAnnonce.getEmailUser();
String partel = currentAnnonce.getPartel();
String parmail = currentAnnonce.getParmail();
Intent myIntent = new Intent(Main_All_Annonces.this, Detail_annonce.class);
myIntent.putExtra("titre", titre);
myIntent.putExtra("cat", cat);
myIntent.putExtra("desc", desc);
myIntent.putExtra("etat", etat);
myIntent.putExtra("img", img);
myIntent.putExtra("prix", prix);
myIntent.putExtra("villeObj", villeObj);
myIntent.putExtra("codePostal", codePostal);
myIntent.putExtra("departement", departement);
myIntent.putExtra("avatarUser", avatarUser);
myIntent.putExtra("pseudoUser", pseudoUser);
myIntent.putExtra("dateDebut", dateDebut);
myIntent.putExtra("idAnnonce", idAnnonce);
myIntent.putExtra("emailUser", emailUser);
myIntent.putExtra("partel", partel);
myIntent.putExtra("parmail", parmail);
myIntent.putExtra("parentAct", "AllAnnonces");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String transitionName = (String) view.getTag(R.id.allannonces_image);
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(
Main_All_Annonces.this,
view, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
// put more extras in the intent if you want, like the object clicked
myIntent.putExtra("EXTRA_IMAGE_TRANSITION_NAME", transitionName);
ActivityCompat.startActivity(Main_All_Annonces.this, myIntent, options.toBundle());
}
else {
// Code to run on older devices
startActivity(myIntent);
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}
}
});
そして、Activity2 の onCreate 内のコード:
ViewCompat.setTransitionName(image_txt, getIntent().getStringExtra("EXTRA_IMAGE_TRANSITION_NAME"));
imageLoader.displayImage(img, image_txt);
activity2 のレイアウトで宣言された imageview の抜粋:
<ImageView
android:id="@+id/detail_annonce_image"
android:transitionName="transitionImg"
android:layout_width="fill_parent"
android:layout_height="280dp"
android:scaleType="centerCrop"
android:src="@drawable/cover1" />