Search code examples
androidanimationanimated-gif

How to display .GIF file in full screen android


I want to implement .Gif file in my splash screen ,i done that, But it does not diply with full screen it shows top left corner of the screen,please give the solution

My code:

  <com.App.app.PlayGifView
    android:id="@+id/viewGif"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   />

inActivity

   PlayGifView pGif = (PlayGifView) findViewById(R.id.viewGif);
    pGif.setImageResource(R.drawable.transit);

GifActivity:

   i get this sample code from google 

  public class PlayGifView extends View {
  private static final int DEFAULT_MOVIEW_DURATION = 1000;
  private int mMovieResourceId;
  private Movie mMovie;
  private long mMovieStart = 0;
  private int mCurrentAnimationTime = 0;
   @SuppressLint("NewApi")
   public PlayGifView(Context context, AttributeSet attrs) {
    super(context, attrs);

    /**
     * Starting from HONEYCOMB have to turn off HardWare acceleration to  draw
     * Movie on Canvas.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
   }

//herei pass my gif file

 public void setImageResource(int mvId){
    this.mMovieResourceId = mvId;
    mMovie =      Movie.decodeStream(getResources().openRawResource(mMovieResourceId));
    requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if(mMovie != null){
        setMeasuredDimension(mMovie.width(), mMovie.height());
    }else{
        setMeasuredDimension(getSuggestedMinimumWidth(), getSuggestedMinimumHeight());
    }
}

@Override

 protected void onDraw(Canvas canvas) {
    if (mMovie != null){
        updateAnimtionTime();
        drawGif(canvas);
        invalidate();
    }else{
        drawGif(canvas);
    }
}

private void updateAnimtionTime() {
    long now = android.os.SystemClock.uptimeMillis();

    if (mMovieStart == 0) {
        mMovieStart = now;
    }
    int dur = mMovie.duration();
    if (dur == 0) {
        dur = DEFAULT_MOVIEW_DURATION;
    }
    mCurrentAnimationTime = (int) ((now - mMovieStart) % dur);
}

private void drawGif(Canvas canvas) {
    mMovie.setTime(mCurrentAnimationTime);
    mMovie.draw(canvas, 0, 0);
    canvas.restore();
}
}

Solution

  • <SurfaceView
    android:id="@+id/mygif"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:scaleType="fitXY"/>

    surfaceView = (SurfaceView)findViewById(R.id.mygif);
    GifRun gifRun = new GifRun();
    gifRun.LoadGiff(surfaceView, this, R.drawable.splashgif);