android 圆角图片,android中的一个圆角图片

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.

54639684f238cdad9a6332f5fed16ea2.png 980ca8c3f6772d194cae6a5de5bfca07.png

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:

repositories {

mavenCentral()

}

dependencies {

compile ‘com.makeramen:roundedimageview:2.2.0‘

}

Usage

Define in xml:

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/imageView1"

android:src="@drawable/photo1"

android:scaleType="fitCenter"

app:riv_corner_radius="30dip"

app:riv_border_width="2dip"

app:riv_border_color="#333333"

app:riv_mutate_background="true"

app:riv_tile_mode="repeat"

app:riv_oval="true" />

Or in code:

RoundedImageView riv = new RoundedImageView(context);

riv.setScaleType(ScaleType.CENTER_CROP);

riv.setCornerRadius((float) 10);

riv.setBorderWidth((float) 2);

riv.setBorderColor(Color.DKGRAY);

riv.mutateBackground(true);

riv.setImageDrawable(drawable);

riv.setBackground(backgroundDrawable);

riv.setOval(true);

riv.setTileModeX(Shader.TileMode.REPEAT);

riv.setTileModeY(Shader.TileMode.REPEAT);

Or make a Transformation for Picasso:

Transformation transformation = new RoundedTransformationBuilder()

.borderColor(Color.BLACK)

.borderWidthDp(3)

.cornerRadiusDp(30)

.oval(false)

.build();

Picasso.with(context)

.load(url)

.fit()

.transform(transformation)

.into(imageView);

Changelog

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

原文:http://www.cnblogs.com/ArRan/p/4766067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值