[Android Pro] Android 必知必会-使用 supportV4 的 RoundedBitmapDrawable 实现圆角

本文介绍了RoundedBitmapDrawable类的功能及用法,该类属于android.support.v4.graphics.drawable包,可用于实现图片的圆角和圆形效果,无需依赖第三方库。文中详细解释了setCircular和setCornerRadius两个关键方法。

RoundedBitmapDrawable 是 supportV4 下的一个类,有了它,显示圆角和圆形图片的情况下就不需要额外的第三方类库了,还能和各种图片加载库配合使用。

背景

今天无意间看到一段实现圆形头像的代码:

1
2
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
drawable.setCircular( true );

RoundedBitmapDrawable 这个类顿时就引起我的好奇了,一查发现是android.support.v4.graphics.drawable.RoundedBitmapDrawable ,点击此处 可以看到官方的介绍。这个类中的两个方法是今天的主角:

returnmethod
void setCircular(boolean circular) : Sets the image shape to circular.
void setCornerRadius(float cornerRadius) : Sets the corner radius to be applied when drawing the bitmap.

setCircular(boolean circular) : 把图片的形状设为圆形;

setCornerRadius(float cornerRadius) : 设置图片的圆角半径。

分类:  Android Pro
本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/6397727.html如需转载请自行联系原作者

demoblog
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值