我有這個變量:Android:在Java中按下時如何停止GIF圖像按鈕的動畫?
GifImageButton buttonGifImage = new GifImageButton(this);
我添加它GIF動畫:
buttonGifImage.setBackgroundResource(R.drawable.gifImage);
當我打開這個代碼,我看到動畫。當我按下此按鈕時,我想停止動畫。我試過,但沒有奏效:
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
}
}
}
有沒有好的辦法阻止動畫?(考慮我想再次激活動畫)。
或者我必須從這個gif圖像創建一個png圖像,並用此png調用setBackgroundResource ..?
我試圖避免2幅圖像(GIF和PNG)爲發揮節約\停止gif動畫..
========編輯======= =
我的依賴關係:
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'
}
我的資料庫:
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
您使用GifImageButton的哪個庫? –
我加了編輯的問題。如果它沒有回答你的問題,你能告訴我如何檢查它嗎? –