CircleImageView README

The project's README from github.com/hdodenhof/CircleImageView. As one markdown file: README.md.

CircleImageView

A fast circular ImageView perfect for profile images. This is based on RoundedImageView from Vince Mi which itself is based on techniques recommended by Romain Guy.

CircleImageView

It uses a BitmapShader and does not:

As this is just a custom ImageView and not a custom Drawable or a combination of both, it can be used with all kinds of drawables, i.e. a PicassoDrawable from Picasso or other non-standard drawables (needs some testing though).

Gradle

dependencies {
    ...
    implementation 'de.hdodenhof:circleimageview:3.1.0'
}

Usage

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:src="@drawable/profile"
    app:civ_border_width="2dp"
    app:civ_border_color="#FF000000"/>

Limitations

FAQ

How can I use a VectorDrawable with CircleImageView?

Short answer: you shouldn't. Using a VectorDrawable with CircleImageView is very inefficient. You should modify your vectors to be in a circular shape and use them with a regular ImageView instead.

Why doesn't CircleImageView extend AppCompatImageView?

Extending AppCompatImageView would require adding a runtime dependency for the support library without any real benefit.

How can I add a selector (e.g. ripple effect) bound to a circle?

There's currently no direct support for a circle bound selector but you can follow these steps to implement it yourself.

How can I add a gap between image and border?

Adding a gap is also not supported directly but there's a workaround.

Changelog

License

Copyright 2014 - 2020 Henning Dodenhof

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

CircleImageView (hdodenhof/CircleImageView)

Searching Database…

这是什么东西?CircleImageView 是一个用于 Android 的高速圆形 ImageView,专为头像图片设计。它是一个自定义 View,可以直接放进你的布局里,代替标准的 ImageView。
它和普通的 ImageView 有什么区别?它通过 BitmapShader 把图片渲染成圆形——不复制位图、不用 clipPath、也不用 setXfermode 做二次绘制,所以速度很快。作为一个自定义 ImageView,它可以接受任何 drawable,包括 Picasso 加载的图片。
怎么把它添加到我的项目里?把 README 的 Gradle 部分里的 Gradle 依赖添加到你应用的 build.gradle 中。3.x 版本基于 AndroidX,所以要在 AndroidX 项目中使用。
它会引入其他额外的库吗?不会——作者有意不继承 AppCompatImageView,因为那样会额外引入对 support library 的运行时依赖,却没有实际好处。
我能修改 ScaleType 或者使用 adjustViewBounds 吗?不能。ScaleType 固定为 CENTER_CROP,修改它会抛出异常;adjustViewBounds 也不受支持——这是刻意的设计,因为它面向的是头像图片。
圆形部分可以自定义哪些东西?边框颜色和宽度、圆形背景色、内边距(padding)以及 elevation。它的 XML 属性都以 'civ' 为前缀,比如 civ_border_width。
点击圆形以外的地方会有反应吗?不会——从 3.0.0 开始,触摸事件的处理范围仅限于圆形区域,圆形图片之外的触摸不会作用于这个 View。
可以在里面用 VectorDrawable 吗?不建议——通过它渲染矢量图效率非常低。README 建议把矢量图改造成圆形形状,然后用普通的 ImageView 来显示。
从 2.x 升级到 3.x 麻烦吗?基本上不麻烦,但 3.0.0 把库迁移到了 AndroidX,并移除了所有已废弃的属性和方法,所以切换时要更新你的 import 以及用到废弃 API 的调用。
Creator
hdodenhof
Size
1 MB
Stars
14.5K
Updated
CommitJan 10
Age
12y
Commits · 90 Days