How to make an ImageView with rounded corners?

前端 未结 30 2478
天涯浪人
天涯浪人 2020-11-21 05:39

In Android, an ImageView is a rectangle by default. How can I make it a rounded rectangle (clip off all 4 corners of my Bitmap to be rounded rectangles) in the ImageView?

30条回答
  •  死守一世寂寞
    2020-11-21 06:18

    Rounded image Using ImageLoader here

    Create DisplayImageOptions:

    DisplayImageOptions options = new DisplayImageOptions.Builder()
        // this will make circle, pass the width of image 
        .displayer(new RoundedBitmapDisplayer(getResources().getDimensionPixelSize(R.dimen.image_dimen_menu))) 
        .cacheOnDisc(true)
        .build();
    
    imageLoader.displayImage(url_for_image,ImageView,options);
    

    Or you can user Picasso Library from Square.

    Picasso.with(mContext)
        .load(com.app.utility.Constants.BASE_URL+b.image)
        .placeholder(R.drawable.profile)
        .error(R.drawable.profile)
        .transform(new RoundedTransformation(50, 4))
        .resizeDimen(R.dimen.list_detail_image_size, R.dimen.list_detail_image_size)
        .centerCrop()
        .into(v.im_user);
    

    you can download RoundedTransformation file here here

提交回复
热议问题