Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this hope you find interesting ..</p> <p>here is code for activity ...</p> <pre><code>package test.example; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class AminationDemo extends Activity implements OnClickListener { ImageView img; Button strtbtn,stpbtn; AnimationDrawable mAnimation; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView) findViewById(R.id.iv); BitmapDrawable frame0 = (BitmapDrawable)getResources().getDrawable(R.drawable.f0); BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.f1); BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.f2); BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.f3); BitmapDrawable frame4 = (BitmapDrawable)getResources().getDrawable(R.drawable.f4); BitmapDrawable frame5 = (BitmapDrawable)getResources().getDrawable(R.drawable.f5); int reasonableDuration = 750; mAnimation = new AnimationDrawable(); mAnimation.addFrame(frame0, reasonableDuration); mAnimation.addFrame(frame1, reasonableDuration); mAnimation.addFrame(frame2, reasonableDuration); mAnimation.addFrame(frame3, reasonableDuration); mAnimation.addFrame(frame4, reasonableDuration); mAnimation.addFrame(frame5, reasonableDuration); img.setBackgroundDrawable(mAnimation); strtbtn = (Button) findViewById(R.id.strtbtn); strtbtn.setOnClickListener(this); stpbtn = (Button) findViewById(R.id.stpbtn); stpbtn.setOnClickListener(this); } @Override public void onClick(View v) { if(v.getId()== R.id.strtbtn){ mAnimation.start(); mAnimation.setOneShot(false); } else mAnimation.stop(); } } </code></pre> <p>the layout main ... </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ImageView android:id="@+id/iv" android:layout_width="400dp" android:layout_height="250dp" /&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/strtbtn" android:layout_width="wrap_content" android:text="start" /&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/stpbtn" android:layout_width="wrap_content" android:text="stop" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here are frames for example or you can create your own ...(put in drawable with name f0,f1,...)</p> <p><img src="https://i.stack.imgur.com/86ZYK.png" alt="first frame"></p> <p><img src="https://i.stack.imgur.com/x9t6r.png" alt="second frame"></p> <p><img src="https://i.stack.imgur.com/mPb16.png" alt="Third frame"></p> <p><img src="https://i.stack.imgur.com/hLGfR.png" alt="Fourth frame"></p> <p><img src="https://i.stack.imgur.com/O6t1n.png" alt="Fifth frame"></p> <p><img src="https://i.stack.imgur.com/ct1w2.png" alt="Sixth frame"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload