您的位置:首页 > 移动开发 > Android开发

Android——圆角的几种方式

2016-03-15 14:36 337 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/Jimmy1Chung/article/details/50896293

1.Shape drawable

res/drawable/round_outline.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dp" />
</shape>

设置ImageView的background,src即可

2.

Xfermode

主要代码:

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

3.

BitmapShader

主要代码:

paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

4.
RoundedBitmapDrawable
需要加上v21 of the Support library
主要代码:
RoundedBitmapDrawabledr = RoundedBitmapDrawableFactory.create(res, src);
dr.setCornerRadius(cornerRadius);

5.第三方库

(1)ImageLoader

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();

(2) Picasso
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);






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: