生成圆形头像

<html>
<head>
<title>圆形头像</title>
<style type="text/css">
.radius{width:100px;height:100px;
        -moz-border-radius:50px;
        -webkit-border-radius:50px;
        border:solid 1px #aaa;
        border-radius:50px;
        -khtml-border-radius:50px;}
</style>
</head>
<body>

<img src="http://avatar.csdn.net/F/5/E/2_baidu_21029481.jpg" class="radius" />
</body>
</htm>

生成圆形、方形、及方形的组合头像。项目地址:https://github.com/Pedroafa/avatar-android 效果图:如何使用:首先创建个ImageView<ImageView             android:id="@ id/roundedAvatar"             android:layout_height="fill_parent"             android:layout_width="fill_parent"/>2. //通过AvatarDrawableFactory生成各种形状的Drawable AvatarDrawableFactory avatarDrawableFactory = new AvatarDrawableFactory(getResources()); BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = false; Bitmap avatar = BitmapFactory.decodeResource(getResources(), R.drawable.avatar, options); //圆形的 Drawable roundedAvatarDrawable = avatarDrawableFactory.getRoundedAvatarDrawable(avatar);//生成圆形的Drawable ImageView roundedAvatarView = (ImageView)rootView.findViewById(R.id.roundedAvatar); roundedAvatarView.setImageDrawable(roundedAvatarDrawable);其他形状的://圆形的且带边框的 Drawable borderedRoundedAvatarDrawable = avatarDrawableFactory.getBorderedRoundedAvatarDrawable(avatar); ImageView borderedRoundedAvatarView = (ImageView)rootView.findViewById(R.id.borderedRoundedAvatar); borderedRoundedAvatarView.setImageDrawable(borderedRoundedAvatarDrawable); //方形的 Drawable squaredAvatarDrawable = avatarDrawableFactory.getSquaredAvatarDrawable(avatar); ImageView squaredAvatarView = (ImageView)rootView.findViewById(R.id.squaredAvatar); squaredAvatarView.setImageDrawable(squaredAvatarDrawable); //俩个方形的组合头像 Drawable doubleSquaredAvatarDrawable = avatarDrawableFactory.getSquaredAvatarDrawable(avatar, avatar); ImageView doubleSquaredAvatarView = (ImageView)rootView.findViewById(R.id.doubleSquaredAvatar); doubleSquaredAvatarView.setImageDrawable(doubleSquaredAvatarDrawable); //三个方形的组合头像 Drawable tripleSquaredAvatarDrawable = avatarDrawableFactory.getSquaredAvatarDrawable(avatar, avatar, avatar); ImageView tripleSquaredAvatarView = (ImageView)rootView.findViewById(R.id.tripleSquaredAvatar); tripleSquaredAvatarView.setImageDrawable(tripleSquaredAvatarDrawable); //四个方形的组合头像 Drawable quadrupleSquaredAvatarDrawable = avatarDrawableFactory                     .getSquaredAvatarDrawable(avatar, avatar, avatar, avatar); ImageView quadrupleSquaredAvatarView = (ImageView)rootView.findViewById(R.id.quadrupleSquaredAvatar); quadrupleSquaredAvatarView.setImageDrawable(quadrupleSquaredAvatarDrawable);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值