How to round an image with Glide library?

前端 未结 22 1853
悲哀的现实
悲哀的现实 2020-11-28 00:46

So, anybody know how to display an image with rounded corners with Glide? I am loading an image with Glide, but I don\'t know how to pass rounded params to this library.

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 00:54

    its very simple i have seen Glide library its very good library and essay base on volley Google's library

    usethis library for rounded image view

    https://github.com/hdodenhof/CircleImageView

    now

    //For a simple view:

     @Override
     public void onCreate(Bundle savedInstanceState) {
      ...
    
      CircleImageView civProfilePic = (CircleImageView)findViewById(R.id.ivProfile);
      Glide.load("http://goo.gl/h8qOq7").into(civProfilePic);
    }
    

    //For a list:

    @Override
    public View getView(int position, View recycled, ViewGroup container) {
    final ImageView myImageView;
     if (recycled == null) {
        myImageView = (CircleImageView) inflater.inflate(R.layout.my_image_view,
                container, false);
    } else {
        myImageView = (CircleImageView) recycled;
    }
    
    String url = myUrls.get(position);
    
    Glide.load(url)
        .centerCrop()
        .placeholder(R.drawable.loading_spinner)
        .animate(R.anim.fade_in)
        .into(myImageView);
    
      return myImageView;
    }
    

    and in XML

    
    

提交回复
热议问题