android - Position View X Y and translate animation to an Original location -
i trying animation small circle goes next screen clicked. have custom list view, 2 text views. 1 of textview in circle background.
now on click event listitem following code triggered :
intent intent = new intent(v.getcontext(), detailactivity.class); int[] location = new int[2]; holder.initialview.getlocationinwindow(location); intent.putextra("location", location); intent.putextra("initialtext", holder.initialview.gettext()); context.startactivity(intent);
in above code getting location in windows of initialtextview, i.e. circle background, , pass same detailactivity.
inside of detailactivity, onresume, have following code:
private textview minitialtextview; private string minitialtext; private int[] listitemlocation; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_detail); listitemlocation = getintent().getintarrayextra("location"); minitialtext = getintent().getstringextra("initialtext"); minitialtextview = (textview) findviewbyid(r.id.initial); } @override protected void onresume() { super.onresume(); minitialtextview.post(new runnable() { @override public void run() { int[] location = new int[2]; minitialtextview.getlocationonscreen(location); float x = location[0]; float y = location[1]; minitialtextview.setx(listitemlocation[0]); minitialtextview.sety(listitemlocation[1]); minitialtextview.settext(minitialtext); minitialtextview.animate().translationx(x) .translationy(y).setduration(1000).setstartdelay(100); } }); }
detailactivity - layout file
<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:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.architectpack.animate.detailactivity"> <textview android:id="@+id/initial" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="32dp" android:layout_gravity="center" android:gravity="center" android:text="am" android:background="@drawable/circle_background" /> </relativelayout>
however, not working. not calculating positions correctly.
any appreciated.
Comments
Post a Comment