java - ListView Shared Element Transition Issue -
i attempting create shared element transition between 2 activities. appears work find between 2 layouts, each containing single imageview. however, having issues getting transition work listview.
the issue when user taps on first row, transition work expected. however, when second row tapped, origin of transition appears image of first row well!
i have created simple list view custom row layout:
row_detailed.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="daft punk" android:id="@+id/primary_textview" android:layout_gravity="center_horizontal" android:layout_weight="0.07" android:layout_aligntop="@+id/primary_imageview" android:layout_torightof="@+id/primary_imageview" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="random access memories" android:id="@+id/textview4" android:layout_gravity="center_horizontal" android:layout_weight="0.07" android:layout_alignbottom="@+id/primary_imageview" android:layout_torightof="@+id/primary_imageview" /> <imageview android:layout_width="84dp" android:layout_height="84dp" android:id="@+id/primary_imageview" android:src="@drawable/ram" android:layout_weight="0.07" /> </relativelayout>
the layout secondary activity, activity_transition_secondary.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="legiocode.com.tapstrprototype.activity.transitionsecondaryactivity"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/secondary_imageview" android:src="@drawable/ram" android:layout_alignparenttop="true" android:layout_alignparentstart="true" android:layout_alignparentend="true" /> </relativelayout>
the primary activity, transitionprimaryactivity.java:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_transition_primary); listview listview = (listview)findviewbyid(r.id.listview2); arrayadapter<string> adapter = new arrayadapter(this, r.layout.row_detailed, r.id.primary_textview, items); listview.setadapter(adapter); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { string transitionname = getstring(r.string.transition_image) + string.format("_%d", i); imageview imageview = (imageview)findviewbyid(r.id.primary_imageview); imageview.settransitionname(transitionname); intent intent = new intent(transitionprimaryactivity.this, transitionsecondaryactivity.class); intent.putextra(transitionsecondaryactivity.transition_name, transitionname); activityoptionscompat options = activityoptionscompat.makescenetransitionanimation(transitionprimaryactivity.this, imageview, // view starts transition transitionname // transitionname of view we’re transitioning ); activitycompat.startactivity(transitionprimaryactivity.this, intent, options.tobundle()); } }); }
the secondary activity, transitionsecondaryactivity.java:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_transition_secondary); string transitionname = getintent().getstringextra(transition_name); imageview imageview = (imageview)findviewbyid(r.id.secondary_imageview); imageview.settransitionname(transitionname); }
i have tried implement transition names dynamically, doesn't seem make of difference. setting transition correctly?
you have access clicked view (in case parameter view) in
onitemclick(adapterview<?> adapterview, view view, int i, long l)
with
imageview imageview = (imageview)findviewbyid(r.id.primary_imageview);
you access first element in list.
ps: put transition names inside xml. makes more easy read.
Comments
Post a Comment