i trying add animation linear layout. below code :-
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/mylinearlayout" android:weightsum="1"> <imageview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/imageview1" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:scaletype="centercrop" android:layout_weight="0.5" android:src="@mipmap/ic_launcher"/> <view android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/offerimage" android:layout_centerhorizontal="true" android:layout_margintop="50dp" android:layout_weight="0.5" android:layout_gravity="center_horizontal" android:text="large text" android:textappearance="?android:attr/textappearancelarge" /> <button android:id="@+id/startanimation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/offerimage" android:layout_centerhorizontal="true" android:layout_margintop="50dp" android:layout_weight="0.5" android:layout_gravity="center_horizontal" android:text="start" /> </linearlayout> </linearlayout>
inside activity's oncreate method,
@override protected void oncreate(bundle savedinstancestate) { . . . linearlayout ll_mainlayout = (linearlayout)findviewbyid(r.id.mylinearlayout); textview tv_data = (textview) findviewbyid(r.id.textview1); button btn_startanimation = (button)findviewbyid(r.id.startanimation); tv_data.settext("before animation"); btn_startanimation.setonclicklistner(new view.onclicklistener(){ @override public void onclick(view v) { animation animation = animationutils.loadanimation(getapplicationcontext(),r.anim.move); ll_mainlayout.setanimation(animation); ll_mainlayout.setlayoutanimationlistener(new animation.animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation animation) { showdata(); } @override public void onanimationrepeat(animation animation) { } }); } }); } public void showdata() { tv_data.settext("after animation"); } }
i can see animation happening after animation tv_data textview doesn't change "after animation";
please help
set animationlistener on animation object instead:
animation.setanimationlistener(new animation.animationlistener() { @override public void onanimationend (animation animation) { showdata(); } @override public void onanimationrepeat (animation animation) {} @override public void onanimationstart (animation animation) {} });
also, use startanimation()
instead of setanimation()
on ll_mainlayout
, if want start immediately.
Comments
Post a Comment