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Io/v0NjIJeqfZtE1sdHhO14058/m2QTBJ/fMhMzH5Mx99Hp3+HV4482AEzsemaj+Zph8zE9O52eDk8hpCw1S1hgu3QzATbNjPBts1MsG0zE2zbzATbNjPBts1MsG0zE2zbzATbNjPBts1MsG0zE2zbzATbNjPBtv0fqEaE/39lDLoAAAAASUVORK5CYII=" alt="" />

2.  自定义的控件类

package com.chaowen.yixin;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView; public class RoundedImageView extends ImageView { public RoundedImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
} public RoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
} public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} @Override
protected void onDraw(Canvas canvas) { Drawable drawable = getDrawable(); if (drawable == null) {
return;
} if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable)drawable).getBitmap() ;
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true); int w = getWidth(), h = getHeight(); Bitmap roundBitmap = getCroppedBitmap(bitmap, w);
canvas.drawBitmap(roundBitmap, 0,0, null); } public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
Bitmap sbmp;
if(bmp.getWidth() != radius || bmp.getHeight() != radius)
sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
else
sbmp = bmp;
Bitmap output = Bitmap.createBitmap(sbmp.getWidth(),
sbmp.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output); final int color = 0xffa19774;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f,
sbmp.getWidth() / 2+0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(sbmp, rect, rect, paint); return output;
} }

3.   使用控件

<com.chaowen.yixin.RoundedImageView
android:id="@+id/headImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25.0dip"
android:adjustViewBounds="true"
android:maxHeight="80dip"
android:maxWidth="80dip"
android:src="@drawable/head_default_yixin" />

4.  ok  大功告成

Android -- 自定义ImageView(圆形头像)的更多相关文章

  1. Android自定义ImageView圆形头像

    效果图: 代码如下: RoundImageView.java import cn.comnav.evaluationsystem.R; import android.content.Context; ...

  2. Android ImageView圆形头像

    转载自:http://m.oschina.net/blog/321024 Android ImageView圆形头像 图片完全解析 我们在做项目的时候会用到圆形的图片,比如用户头像,类似QQ.用户在用 ...

  3. 【转】Android ImageView圆形头像

    Android ImageView圆形头像 图片完全解析 我们在做项目的时候会用到圆形的图片,比如用户头像,类似QQ.用户在用QQ更换头像的时候,上传的图片都是矩形的,但显示的时候确是圆形的. 原理: ...

  4. Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示

    Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android实现圆角矩形,圆形或者椭圆等图形,一般通过自定义ImageView来实现,首先获取到图片的Bitmap,然后通过 ...

  5. 【Android】自己定义圆形ImageView(圆形头像 可指定大小)

    近期在仿手Q的UI,这里面常常要用到的就是圆形头像,看到 在android中画圆形图片的几种办法 这篇文章,了解了制作这样的头像的原理.只是里面提供的方法另一个不足的地方就是不能依据实际需求改变图片的 ...

  6. Android 自定义 View 圆形进度条总结

    Android 自定义圆形进度条总结 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 微信公众号:牙锅子 源码:CircleProgress 文中如有纰漏,欢迎大家留言指出. 最近 ...

  7. Android 自定义ImageView支持缩放,拖拽,方便复用

    今天刚发了一篇关于ImageView的缩放和拖拽的博客,然后我想了下,将他自定义下,方便我们来复用这个imageView,效果我就不多说了,http://blog.csdn.net/xiaanming ...

  8. Android 自定义view --圆形百分比(进度条)

    转载请注明出处:http://blog.csdn.net/wingichoy/article/details/50334595 注:本文由于是在学习过程中写的,存在大量问题(overdraw onDr ...

  9. android 自定义图片圆形进度条

    感觉话一个圆形进度条挺简单的 ,但是却偏偏给了几张图片让你话,说实话我没接触过,感觉好难,还好百度有大把的资源,一番努力下终于画出来了. 代码如下. package com.etong.cpms.wi ...

随机推荐

  1. SQL集合操作符样例(UNION,INTERSECT,EXCEPT)

    由于MYSQL目前只实现了UNION, 所以后面两个就没得玩罗.... SELECT emp_id, assigned_branch_id -> FROM employee -> WHER ...

  2. 一次Promise 实践:异步任务的分组调度

    起因是在工作中遇到一个问题,可以用一个二维数组简单描述: [[1,2,3],[4,5,6],[7,8,9]] 这里每个数字都代表“一个异步计算任务”, 每个子数组把1个或多个计算任务划分成组,要求是: ...

  3. freemarker 实现对URL的安全编码

    [#setting url_escaping_charset='utf-8'] ${yourstr?url}

  4. C# DatrgridView表格控件的一些用法

    public class useDatrgrivView { string conn = null; string sqlComm = null; DataSet das = null; DataGr ...

  5. 【maven】 pom.xml详解

    pom.xml详解 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  6. LoadRunner常用事务判断

    一.数据值比较 lr_start_transaction("终审") if (atoi(lr_eval_string("{MyOutputParm}"))==a ...

  7. java多线程--实现Runnable接口

    package unit8; import java.applet.Applet; import java.awt.Label; import java.awt.TextField; public c ...

  8. hdu 1024 Max Sum Plus Plus

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. 静态函数(面向过程的static关键字)

    在函数的返回类型前加上static关键字,函数即被定义为静态函数.静态函数与普通函数不同,它只能在声明它的文件中可见,不能被其他文件使用. 静态函数的例子: #include <iostream ...

  10. http://blog.csdn.net/a491057947/article/details/46724707

    http://blog.csdn.net/a491057947/article/details/46724707