RoundedImageView

A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy. RoundedImageView is a full superset of CircleImageView (which is actually just a subset based on this lib) with many more advanced features like support for ovals, rounded rectangles, ScaleTypes and TileModes.

 

There are many ways to create rounded corners in android, but this is the fastest and best one that I know of because it:

  • does not create a copy of the original bitmap
  • does not use a clipPath which is not hardware accelerated and not anti-aliased.
  • does not use setXfermode to clip the bitmap and draw twice to the canvas.

If you know of a better method, let me know (or even better open a pull request)!

Also has proper support for:

  • Borders (with Colors and ColorStateLists)
  • Ovals and Circles
  • All ScaleTypes
    • Borders are drawn at view edge, not bitmap edge
    • Except on edges where the bitmap is smaller than the view
    • Borders are not scaled up/down with the image (correct width and radius are maintained)
  • Anti-aliasing
  • Transparent backgrounds
  • Hardware acceleration
  • Support for LayerDrawables (including TransitionDrawables)
  • TileModes for repeating drawables

Gradle

RoundedImageView is available in Maven Central.

Add the following to your build.gradle to use:

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. compile 'com.makeramen:roundedimageview:2.2.0'
  6. }

Usage

Define in xml:

  1. <com.makeramen.roundedimageview.RoundedImageView
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. android:id="@+id/imageView1"
  4. android:src="@drawable/photo1"
  5. android:scaleType="fitCenter"
  6. app:riv_corner_radius="30dip"
  7. app:riv_border_width="2dip"
  8. app:riv_border_color="#333333"
  9. app:riv_mutate_background="true"
  10. app:riv_tile_mode="repeat"
  11. app:riv_oval="true" />

Or in code:

  1. RoundedImageView riv = new RoundedImageView(context);
  2. riv.setScaleType(ScaleType.CENTER_CROP);
  3. riv.setCornerRadius((float) 10);
  4. riv.setBorderWidth((float) 2);
  5. riv.setBorderColor(Color.DKGRAY);
  6. riv.mutateBackground(true);
  7. riv.setImageDrawable(drawable);
  8. riv.setBackground(backgroundDrawable);
  9. riv.setOval(true);
  10. riv.setTileModeX(Shader.TileMode.REPEAT);
  11. riv.setTileModeY(Shader.TileMode.REPEAT);

Or make a Transformation for Picasso:

  1. Transformation transformation = new RoundedTransformationBuilder()
  2. .borderColor(Color.BLACK)
  3. .borderWidthDp(3)
  4. .cornerRadiusDp(30)
  5. .oval(false)
  6. .build();
  7.  
  8. Picasso.with(context)
  9. .load(url)
  10. .fit()
  11. .transform(transformation)
  12. .into(imageView);

Changelog

see Releases

项目地址:https://github.com/vinc3m1/RoundedImageView

android中的一个圆角图片的更多相关文章

  1. Android中显示gif动态图片

    在android中显示一个静态图片比如png jpg等等都很方便,但是如果要显示一个gif 动态图片就需要进行一些处理. 本文是采用自定义view 然后进行重新onDraw方法来实现 首先自定义Vie ...

  2. Android中实现ListView圆角效果[转]

    本文演示如何Android中实现ListView圆角效果. 无论是网站,还是APP,人们都爱看一些新颖的视图效果.直角看多了,就想看看圆角,这几年刮起了一阵阵的圆角设计风:CSS新标准纳入圆角元素,特 ...

  3. android中的文件(图片)上传

    android中的文件(图片)上传其实没什么复杂的,主要是对 multipart/form-data 协议要有所了解. 关于 multipart/form-data 协议,在 RFC文档中有详细的描述 ...

  4. Android中使用ImageViewSwitcher实现图片切换轮播导航效果

    前面写过了使用ViewFlipper和ViewPager实现屏幕中视图切换的效果(ViewPager未实现轮播)附链接: Android中使用ViewFlipper实现屏幕切换 Android中使用V ...

  5. Android中轻松显示Gif图片

    android中现在没有直接显示gif的view,只能通过mediaplay来显示,且还常常不能正常显示出来,为此写了这个gifview,其用法和imageview一样使用方法:1-把GifView. ...

  6. Android UI技巧(一)——Android中伸缩自如的9patch图片切法,没有美工自给自足

    Android UI技巧(一)--Android中伸缩自如的点9图片切法,没有美工自给自足 相信大家对.9 图片应该都很熟悉吧,有些人可能自己都会了,此篇献给那些不会的同学,咱们一起来聊聊.9图片的切 ...

  7. Android 自己写一个打开图片的Activity

    根据记忆中eoe的Intent相关视频,模仿,写一个打开图片的Activity 1.在主Activity的button时间中,通过设置action.category.data打开一个图片.这时代码已经 ...

  8. Android中高效的显示图片之一 ——加载大图

    在网上看了不少文章,发现还是官方文档介绍最详细,把重要的东西简单摘要出来.详细可看官方文档地址 ( http://www.bangchui.org/read.php?tid=9 ) . 在应用中显示图 ...

  9. Android中高效的显示图片之三——缓存图片

    加载一张图片到UI相对比较简单,如果一次要加载一组图片,就会变得麻烦很多.像ListView,GridView,ViewPager等控件,需要显示的图片和将要显示的图片数量可能会很大. 为了减少内存使 ...

随机推荐

  1. 请问使用jmeter在tcp取样器测试中服务器名称或ip,端口可以填变量值吗?

    请问使用jmeter在tcp取样器测试中服务器名称或ip,端口可以填变量值吗?

  2. windows下hadoop安装配置(转载)

    Windows平台安装配置Hadoop 步骤: 1. JDK安装(不会的戳这) 2. 下载hadoop2.5.2.tar.gz,或者自行去百度下载. 3. 下载hadooponwindows-mast ...

  3. 2016"百度之星" - 初赛(Astar Round2B)1003 瞬间移动 组合数学+逆元

    瞬间移动  Accepts: 1018  Submissions: 3620  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 65536/ ...

  4. c++ 容器排序

    #include <algorithm> #include <functional> #include <array> #include <iostream& ...

  5. Java 字节的常用封装

    一. Java 的字节 byte (字节) 是 Java 中的基本数据类型,一个 byte 包含8个 bit(位),byte 的取值范围是-128到+127. byte 跟 Java 其他基本类型的关 ...

  6. java网络编程之Socket编程

    概念 网络编程分为BIO(传统IO).NIO.AIO.Socket编程属于BIO这种传统IO. InetAddress java.net.InetAddress是JAVA中管理IP地址的类,常用 pu ...

  7. 在Linux和Windows系统上安装Nginx服务器的教程

    在Linux和Windows系统上安装Nginx服务器的教程  1.在CentOS系统上安装Nginx 在 CentOS6 版本的 EPEL 源中,已经加入了 nginx 的 rpm 包,不过此 RP ...

  8. linux下升级npm以及node

    npm升级 废话不多说,直接讲步骤.先从容易的开始,升级npm. npm这款包管理工具虽然一直被人们诟病,很多人都推荐使用yarn,但其使用人数还是不见减少,况且npm都是随node同时安装好的,一时 ...

  9. IOS UIApplication和AppDelegate 关系

    UIApplication.AppDelegate.委托等的关系?  什么是委托?为什么要有委托?委托在Iphone中的实现机制是怎样的? 一般来说,我们创建了一个Iphone项目,默认会有这个mai ...

  10. powerdesigner安装图解