zoukankan      html  css  js  c++  java
  • Glide加载图片的事例

    //获取图片的url
                String url = resultsEntity.getUrl();
                //判断获取的图片是否存在
                if (resultsEntity.getItemHeight() > 0) {
                    ViewGroup.LayoutParams layoutParams = viewHolder.rlRoot.getLayoutParams();
                    layoutParams.height = resultsEntity.getItemHeight();
                }
                //设置默认的图片    
                viewHolder.image.setImageResource(R.drawable.pic_gray_bg);
                RequestOptions options = new RequestOptions();
                //设置图片的展示样式
                options.fitCenter();
                //设置备用图片的展示
                options.placeholder(R.drawable.pic_gray_bg);
                //设置缓存
                options.diskCacheStrategy(DiskCacheStrategy.ALL);
                //Glide加载图片
                Glide.with(context)
                        .asBitmap()
                        .load(url)
                        .apply(options)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                int width = resource.getWidth();
                                int height = resource.getHeight();
                                //计算高宽比
                                int finalHeight = (screenWidth / 2) * height / width;
                                if (resultsEntity.getItemHeight() <= 0) {
                                    resultsEntity.setItemHeight(finalHeight);
                                    ViewGroup.LayoutParams layoutParams = viewHolder.rlRoot.getLayoutParams();
                                    layoutParams.height = resultsEntity.getItemHeight();
                                }
    
                                viewHolder.image.setImageBitmap(resource);
                            }
                        });
  • 相关阅读:
    C# 委托/Func() 中 GetInvocationList() 方法的使用 | 接收委托多个返回值
    蒋廷黻著《中国近代史》-中国近代屈辱史读后感
    ASP.NET Core 上传多文件 超简单教程
    Python
    Python
    Python
    Python
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/yegong0214/p/7593374.html
Copyright © 2011-2022 走看看