周末愉快
我在活动中使用gif imageview。当我完成并开始活动时,gif imageview会继续显示之前的内容。我不想这样,我想重新启动gif imageview。我该怎么做?请帮帮我。我将分享与gif imageview相关的代码。
我的播放按钮有:
public void play(View v) {
if (mTimerRunning) {
pauseGIF();
} else {
for (int i = 0; i < textArray.length; i++) {
tv[i].setFocusable(false);
tv[i].setClickable(false);
tv[i].setBackgroundColor(Color.TRANSPARENT);
}
nextButton.setVisibility(View.INVISIBLE);
buttonBack.setVisibility(View.INVISIBLE);
favreread.setVisibility(View.INVISIBLE);
startGIF();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
player2 = MediaPlayer.create(getApplicationContext(), R.raw.hop);
player2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
stopPlayer2();
}
});
player2.start();
}
}, 60000);
}
}
暂停:
private void pauseGIF() {
mTimerRunning = false;
if (marka.getDrawable() instanceof Animatable) { //to pause gif
((Animatable) marka.getDrawable()).stop();
}
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
start.setBackgroundDrawable(ContextCompat.getDrawable(Reread1Activity.this, R.drawable.basla) );
} else {
start.setBackground(ContextCompat.getDrawable(Reread1Activity.this, R.drawable.basla));
}
}
开始如果:
private void startGIF() {
start.setVisibility(View.INVISIBLE);
Glide.with(this).asGif().load(R.raw.saat) //setting for gif to inform when finished
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)).listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(final GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
resource.setLoopCount(1);
new Thread(new Runnable() {
@Override
public void run() {
while(true)
if(!resource.isRunning()) {
runOnUiThread(new Runnable() { //to avoid some errors
@Override
public void run() {
mTimerRunning = false;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
start.setBackgroundDrawable(ContextCompat.getDrawable(Reread1Activity.this, R.drawable.basla) );
} else {
start.setBackground(ContextCompat.getDrawable(Reread1Activity.this, R.drawable.basla));
}
}
});
break;
}
}
}).start();
return false;
}
}).into(marka);
mTimerRunning = true;
}
暂无答案!
目前还没有任何答案,快来回答吧!