Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am using the below custom View instead of Image View.</p> <pre><code>public class SampleView extends View { private Movie mMovie; private long mMovieStart; public SampleView(Context context) { super(context); setFocusable(true); java.io.InputStream is; is = context.getResources().openRawResource(R.drawable.girl_dances); mMovie = Movie.decodeStream(is); } public SampleView(Context context, AttributeSet attrSet) { super(context, attrSet); setFocusable(true); java.io.InputStream is; is = context.getResources().openRawResource(R.drawable.girl_dances); mMovie = Movie.decodeStream(is); } public SampleView(Context context, AttributeSet attrSet, int defStyle) { super(context, attrSet, defStyle); setFocusable(true); java.io.InputStream is; is = context.getResources().openRawResource(R.drawable.girl_dances); mMovie = Movie.decodeStream(is); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0x00000000); Paint p = new Paint(); p.setAntiAlias(true); long now = android.os.SystemClock.uptimeMillis(); if (mMovieStart == 0) { // first time mMovieStart = now; } if (mMovie != null) { int dur = mMovie.duration(); if (dur == 0) { dur = 1000; } int relTime = (int) ((now - mMovieStart) % dur); mMovie.setTime(relTime); mMovie.draw(canvas, getWidth() / 2 - mMovie.width() / 2, getHeight() / 2 - mMovie.height() / 2); invalidate(); } } } </code></pre> <p><strong>XML Layout :</strong></p> <pre><code>&lt;com.test.sample.SampleView android:id="@+id/gif_view" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; </code></pre>
 

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