本文整理了Java中com.bumptech.glide.request.target.ViewTarget.clearOnDetach()
方法的一些代码示例,展示了ViewTarget.clearOnDetach()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViewTarget.clearOnDetach()
方法的具体详情如下:
包路径:com.bumptech.glide.request.target.ViewTarget
类名称:ViewTarget
方法名:clearOnDetach
[英]Clears the View's Request when the View is detached from its android.view.Window and restarts the Request when the View is re-attached from its android.view.Window.
This is an experimental API that may be removed in a future version.
Using this method can save memory by allowing Glide to more eagerly clear resources when transitioning screens or swapping adapters in scrolling views. However it also substantially increases the odds that images will not be in memory if users subsequently return to a screen where images were previously loaded. Whether or not this happens will depend on the number of images loaded in the new screen and the size of the memory cache. Increasing the size of the memory cache can improve this behavior but it largely negates the memory benefits of using this method.
Use this method with caution and measure your memory usage to ensure that it's actually improving your memory usage in the cases you care about.
[中]当视图与android分离时,清除视图的请求。看法窗口,并在视图从其android重新连接时重新启动请求。看法窗
这是一个实验性的API,可能会在未来的版本中删除。
使用这种方法可以节省内存,因为在转换屏幕或在滚动视图中交换适配器时,Glide可以更急切地清除资源。然而,如果用户随后返回到之前加载图像的屏幕,则这也大大增加了图像不在内存中的可能性。这种情况是否发生取决于新屏幕中加载的图像数量和内存缓存的大小。增加内存缓存的大小可以改善这种行为,但它在很大程度上否定了使用这种方法的内存优势。
谨慎使用这种方法,并测量你的内存使用情况,以确保在你关心的情况下,它实际上改善了你的内存使用情况。
代码示例来源:origin: bumptech/glide
@Override
public void onBindViewHolder(GifViewHolder holder, int position) {
final Api.GifResult result = results[position];
holder.gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip =
ClipData.newPlainText("giphy_url", result.images.fixed_height.url);
Preconditions.checkNotNull(clipboard).setPrimaryClip(clip);
Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result);
activity.startActivity(fullscreenIntent);
}
});
// clearOnDetach let's us stop animating GifDrawables that RecyclerView hasn't yet recycled
// but that are currently off screen.
requestBuilder.load(result).into(holder.gifView).clearOnDetach();
preloadSizeProvider.setView(holder.gifView);
}
代码示例来源:origin: bumptech/glide
@Test
public void clearOnDetach_moreThanOnce_registersObserverOnce() {
attachStateTarget
.clearOnDetach()
.clearOnDetach();
assertThat(shadowView.attachStateListeners).hasSize(1);
}
代码示例来源:origin: bumptech/glide
@Test
public void clearOnDetach_onDetach_afterMultipleClearOnDetaches_removesListener() {
attachStateTarget
.clearOnDetach()
.clearOnDetach()
.clearOnDetach();
attachStateTarget.onLoadCleared(/*placeholder=*/ null);
attachStateTarget.setRequest(request);
shadowView.callOnDetachedFromWindow();
verify(request, never()).clear();
}
内容来源于网络,如有侵权,请联系作者删除!