Hide the ImageView after the Frame by Frame Animation stops in android -
i applied frame frame animation in image view , use 2 images in frame frame
main.java
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); imageview iv = (imageview) findviewbyid( r.id.imageview1); iv.setbackgroundresource(r.anim.animation); animationdrawable ac= (animationdrawable) iv.getbackground(); ac.start(); //ac.stop(); if(ac.isrunning()==false){ iv.setvisibility(view.invisible); } }
animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1" android:duration="1000"/> <item android:drawable="@drawable/image2" android:duration="1000"/> </animation-list>
activity_main.xml(layout)
<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:background="#000000" 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=".mainactivity" > <imageview android:id="@+id/imageview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" /> </relativelayout>
im confused stop animation , need hide image view after 2 image animated , restart animation later on
i'm working on advertisement images. need show images short duration , later restart again.
if know solution . please me.
imageview iv = (imageview) findviewbyid( r.id.imageview1);
iv.setbackgroundresource(r.anim.animation); animationdrawable ac= (animationdrawable) iv.getbackground(); ac.start();
you can put empty picture last item in animation:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/image1" android:duration="1000"/> <item android:drawable="@drawable/image2" android:duration="1000"/> <item android:drawable="@drawable/dummy" android:duration="1000"/> </animation-list>
and oneshot=true.
to restart , call onclick method , call start again this: button btn1 = (button) findviewbyid(r.id.btn1);
btn1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { imageview iv = (imageview) findviewbyid( r.id.imageview1); iv.setbackgroundresource(r.anim.animation); animationdrawable ac= (animationdrawable) iv.getbackground(); ac.start(); }
Comments
Post a Comment