【问题标题】:Is there any other way to query / load local images in Android?有没有其他方法可以在 Android 中查询/加载本地图像?
【发布时间】:2020-12-16 13:53:48
【问题描述】:

我正在尝试在网格视图中显示本地图像。我希望它加载得更快。因此,我希望它们按组加载,而不是一次获取图像并加载它们。

那么除了下面的代码之外,还有其他方法可以在 Android 中查询/加载本地图片吗?

Cursor cursor = context.getContentResolver()
                       .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,  
                              mProjection, null, null, 
                              MediaStore.Images.Media.DATE_ADDED + " DESC");

【问题讨论】:

    标签: java android android-studio gridview android-image


    【解决方案1】:

    试试Glide

    Glide.with(imageView.getContext())
                            .load(/*file.jpg/png, drawable, url*/)
                            .placeholder(R.drawable.placeholder)// you can remove this line
                            .dontAnimate()
                            .into(imageView);
    

    在你的 gradle(Module: app) 中添加:

    dependencies {
      implementation 'com.github.bumptech.glide:glide:4.11.0'
      annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    }
    

    【讨论】:

    • 感谢您的回答,非常感谢。是的,我正在使用 Glide 库。但我担心的是获取或查询本地图像。有没有办法在滚动时获取数量有限的图像,而不是一次获取所有图像?让我能够更快地加载图像。再次感谢您。
    • 你使用 ArrayAdapter 吗?
    • 如果您可以在getView 方法中加载每个图像,请参见此处的示例abhiandroid.com/ui/gridview
    猜你喜欢
    • 2020-02-22
    • 2012-06-28
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 2018-12-08
    • 2016-12-23
    • 2011-04-25
    • 1970-01-01
    相关资源
    最近更新 更多