文档介绍:CircleImageView用法及源码解析
;;;。希望通过本篇文章的学习,您会对自定义控件及自定义控件中用到的一些类有一定的了解,最后我会把我添加好详细注释的Demo下载地址附上,你也可以一边看我的Demo,一边看这篇文章,效果应该会更好,那么,我们这就开始吧!
CircleImageView在AS中集成及用法
,很简单,如下最后一行:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile ':pat-v7:'
compile ':circleimageview:'
}
配置完了以后,,,它在github上的下载地址如下:https:///hdodenhof/CircleImageView 好吧,集成就讲这么点,很简单。
下面我们讲一下CircleImageView的具体用法,在将具体用法之前,我们先新建一个最新的android项目按照上述集成方法,集成我们的CircleImageView,集成完成后我们就可以在我们的XML布局文件中引入我们的控件了,如下:
<?xml version="" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas./apk/res/android"
xmlns:app="http://schemas./apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<
android:id="@+id/circleImageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="***@mipmap/psb"
app:civ_border_color="***@android:color/holo_red_dark"
app:civ_border_width="5dp" />
</RelativeLayout>
然后将XML文件与Acitivity进行绑定,运行项目就会看到如下结果:
我们还可以在代码中对CircleImageView进行一些设置如禁用图片圆形属性等,这些在下一节CircleImageView中定义的对外的方法中讲解。
CircleImageView中定义的对外的方法
,下边我一一说明:
***@Override
public ScaleType getScaleType() {
return SCALE_TYPE;
}
解释:外部类获取CircleImageView的ScaleType属性。
***@Override
public void setScaleType(ScaleType scaleType) {
if (scaleType != SCALE_TYPE) {
throw new IllegalArgumentException(("ScaleType %s not supported.", scaleType));
}
}
解释:重写父类方法,,给CircleImageView设置ScaleType属性,,抛出异常,;
***@Override
public void setAdjustViewBounds(boolean adjustViewBoun