简体   繁体   English

使用 ImageView 中的上下文滑动

[英]Glide with context from ImageView

Is it bad practice to use the following?使用以下内容是不好的做法吗?

val imageView:ImageView = ...
val uri:Uri = ...
Glide.with(imageView.context).load(uri).into(imageView)

If it is bad practice, why?如果这是不好的做法,为什么?

Glide is aware of it's context type: if it's an activity or application service it will, internally, because the image will become lifecycle aware and glide can optimise all kind of stuff knowing if onPause or onResume was called. Glide 知道它的上下文类型:如果它是一个活动或应用程序服务,它会在内部,因为图像将成为生命周期感知并且 glide 可以优化所有类型的东西,知道是否调用了 onPause 或 onResume。 Glide also allows you to use fragments and views from which it will take the context from. Glide 还允许您使用片段和视图,从中获取上下文。

It's not bad practice since your view's context it's the activity itself which will make your caching work just fine.这是不错的做法,因为您的视图上下文是活动本身,这将使您的缓存工作得很好。 Check this out for more details: https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en查看更多详细信息: https : //inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM