title: Android: how to stop animation for a gif image button when pressed in Java?
body: <p>I've this variable:</p>
  
  <pre><code>GifImageButton buttonGifImage = new GifImageButton(this);
  </code></pre>
  
  <p>I added it an animated gif:</p>
  
  <pre><code>buttonGifImage.setBackgroundResource(R.drawable.gifImage);
  </code></pre>
  
  <p>When I load this code, I see the animation. I want to stop the animation when I press on this button. I tried this but it didn't work:</p>
  
  <pre><code>buttonGifImage.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          if (event.getAction() == MotionEvent.ACTION_BUTTON_PRESS || event.getAction() == MotionEvent.ACTION_DOWN) {
              // Here I would like to stop the animation
              // I want to display the same image but without animating
              buttonGifImage.setFreezesAnimation(true); //not working
              buttonGifImage.clearAnimation(); //not working
          }
      }
  }
  </code></pre>
  
  <p><strong>Is there a good way to stop the animation?</strong> (considering I would like to activate the animation again).</p>
  
  <p><strong>Or must I create a png image from this gif image and call setBackgroundResource with this png..?</strong></p>
  
  <p>I'm trying to avoid the saving of 2 images(gif and png) for play\stop animated gif..</p>
  
  <p><strong>======== EDIT ========</strong></p>
  
  <p><strong>my dependencies:</strong></p>
  
  <pre><code>    dependencies {
          compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.+'
          compile fileTree(dir: 'libs', include: ['*.jar'])
          testCompile 'junit:junit:4.12'
          compile 'com.android.support:appcompat-v7:23.2.1'
          compile 'com.android.support:design:23.2.1'
      }
  </code></pre>
  
  <p><strong>my repositories:</strong></p>
  
  <pre><code>    repositories {
          mavenCentral()
          maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
      }
  </code></pre>