title: How to make the canvas fit the screen
body: <p>I am drawing a canvas in my app but the problem is that the canvas is not of the same size what the screen is. Mostly the canvas is covering only bottom right part of the screen. Whant can be done to make it fit to the screen.?</p>
  
  <p>Here is the screen shot of how its appearing:</p>
  
  <p><img src="https://i.stack.imgur.com/ETOci.png" alt="enter image description here"></p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class AnimationView extends View 
  {
  
      private Movie mMovie;
      private long mMovieStart;
      private static final boolean DECODE_STREAM = true;
      private static byte[] streamToBytes(InputStream is) {
        ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
        byte[] buffer = new byte[1024];
        int len;
        try {
          while ((len = is.read(buffer)) &gt;= 0) {
            os.write(buffer, 0, len);
          }
        } catch (java.io.IOException e) {
        }
        return os.toByteArray();
      }
  
       public AnimationView(Context context,AttributeSet attrs) 
       {
  
        super(context,attrs);
        setFocusable(true);
        java.io.InputStream is;
        is = context.getResources().openRawResource(R.drawable.flag);
        if (DECODE_STREAM) {
          mMovie = Movie.decodeStream(is);
        } else {
          byte[] array = streamToBytes(is);
          mMovie = Movie.decodeByteArray(array, 0, array.length);
        }
      }
      @Override
      public void onDraw(Canvas canvas) {
       long now = android.os.SystemClock.uptimeMillis();
        if (mMovieStart == 0) { // first time
          mMovieStart = now;
        }
        if (mMovie != null) {
          int dur = mMovie.duration();
          if (dur == 0) {
            dur = 3000;
          }
          int relTime = (int) ((now - mMovieStart) % dur);
         Log.d("", "real time :: " +relTime);
          mMovie.setTime(relTime);
  
          int width = this.getWidth()/2; 
          int height = this.getHeight()/2; 
  
          mMovie.draw(canvas, width, height);
          invalidate();
        }
  
  
      }
    }
  </code></pre>
  
  <p>Here is XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#074068"
      android:orientation="vertical" &gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button" /&gt;
  
      &lt;com.androidqa.AnimationView
          android:id="@+id/View"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          android:adjustViewBounds="true"
          android:visibility="gone"
          android:background="#074068" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>